Skip to content

Instantly share code, notes, and snippets.

@snuke
Last active August 29, 2015 14:03
Show Gist options
  • Save snuke/79e0aafd3043f8cc6fab to your computer and use it in GitHub Desktop.
Save snuke/79e0aafd3043f8cc6fab to your computer and use it in GitHub Desktop.
モールス信号暗記ゲーム

-- --- .-. ... . -.-. --- -.. . --. .- -- .

なぜかモールス信号を覚えようと思って作ったゲームです。

なぜC++で作ったのか謎ですが、morse.cppを適当にコンパイルすると良いです。

1行目にMAX_LENという定数がありますが、これはtrainingモードで出てくるモールス信号の長さの制限です。

最初はこれを2にして始めて、覚えたら3にして、覚えたら4にして・・・とやると覚えやすいです。

やり始めたら楽しくなって、1時間くらいで覚えてしまいました。

入力用: http://snuke.main.jp/morse/

###各モードの説明

  • 0 : モールス信号をアルファベットに変換するトレーニング

出てきたモールス信号が表すアルファベットを入力します。

大文字でも小文字でも良いです。

間違えた場合は正しい答えが出てくるので、それを入力すると先に進めます。

  • 1 : アルファベットをモールス信号に変換するトレーニング

出てきたアルファベットを表すモールス信号を'.'と'-'で入力します。

間違えた場合は正しい答えが出てくるので、それを入力すると先に進めます。

  • 2 : モールス信号→アルファベットのタイムアタックモード

合計30個のモールス信号が10個ずつ表示されるので、対応するアルファベットを入力していって下さい。

改行はしても良いですが、スペースを入れたりすると不正解と判定されるので注意して下さい。(手抜き)

不正解1つあたりペナルティは3秒です。

  • 3 : アルファベット→モールス信号のタイムアタックモード

合計30個のアルファベットが10個ずつ表示されるので、対応するモールス信号を入力していって下さい。

スペースとか改行とかで区切って入力すると良いです。

不正解1つあたりペナルティは3秒です。

###タイムアタックモードのsnukeのタイム

モード2:

Time : 28.463s + 0 * 3s = 28.463s

モード3:

Time : 38.487s + 0 * 3s = 38.487s

###おまけ

数字のモールス信号はすごく覚えやすいので書いときます。

1 : .----

2 : ..---

3 : ...--

4 : ....-

5 : .....

6 : -....

7 : --...

8 : ---..

9 : ----.

0 : -----

なんというか、指を折って数を数えるイメージ?

#define MAX_LEN 4
//////////////////////////
#define SET 3
#define C 10
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<map>
#include<set>
#include<iostream>
#include<sstream>
#include<cctype>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n-1; i >= 0; i--)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define snuke srand((unsigned)clock()+(unsigned)time(NULL))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
// Time
#include<sys/time.h>
ll getTime() {
struct timeval tv;
gettimeofday(&tv, NULL);
ll result = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL;
return result;
}
ll start_time, time_limit;
void setTime(){ start_time = getTime();}
ll nowTime(){ return getTime() - start_time;}
bool timeup(){ return nowTime() > time_limit;}
//
const int MX = 100005, INF = 1000010000;
const ll LINF = 1000000000000000000ll;
const double eps = 1e-10;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1}; //<^>v
vector<string> d;
inline void add(string s, char c){
d[c-'A'] = s;
}
void init(){
d.resize(26);
add(".",'E');
add("-",'T');
add("..",'I');
add(".-",'A');
add("-.",'N');
add("--",'M');
add("...",'S');
add("..-",'U');
add(".-.",'R');
add(".--",'W');
add("-..",'D');
add("-.-",'K');
add("--.",'G');
add("---",'O');
add("....",'H');
add("...-",'V');
add("..-.",'F');
add(".-..",'L');
add(".--.",'P');
add(".---",'J');
add("-...",'B');
add("-..-",'X');
add("-.-.",'C');
add("-.--",'Y');
add("--..",'Z');
add("--.-",'Q');
}
char fix(char c){
if(c >= 'A' && c <= 'Z') return c;
return c+'A'-'a';
}
int main(){
snuke;
init();
vi x(26);
rep(i,26) x[i] = i;
//random_shuffle(rng(x));
rep(i,1000) swap(x[i%26],x[rand()%26]);
int point = 0, tot = 0;
cout << "0 : sign - alp training" << endl;
cout << "1 : alp - sign training" << endl;
cout << "2 : sign - alp test" << endl;
cout << "3 : alp - sign test" << endl;
int mode;
cin >> mode;
setTime();
if(mode == 0){
rep(i,26){
char c = x[i]+'A', r;
string s = d[x[i]];
if(sz(s) > MAX_LEN) continue;
tot++;
cout << s << " : "; fflush(stdout);
cin >> r; r = fix(r);
if(r == c){
cout << "correct!" << endl;
point++;
} else {
cout << "wrong... : " << c << " "; fflush(stdout);
while(1){
cin >> r; r = fix(r);
if(r == c) break;
}
}
}
cout << endl << "Score : " << point << " / " << tot << endl;
cout << "Time : ";
printf("%.3f", nowTime()*0.001);
cout << "s" << endl;
} else if(mode == 1) {
rep(i,26){
char c = x[i]+'A';
string s = d[x[i]], r;
if(sz(s) > MAX_LEN) continue;
tot++;
cout << c << " : "; fflush(stdout);
cin >> r;
if(r == s){
cout << "correct!" << endl;
point++;
} else {
cout << "wrong... : " << s << " "; fflush(stdout);
while(1){
cin >> r;
if(r == s) break;
}
}
}
cout << endl << "Score : " << point << " / " << tot << endl;
cout << "Time : ";
printf("%.3f", nowTime()*0.001);
cout << "s" << endl;
} else if(mode == 2) {
rep(si,SET){
vi y;
rep(ci,C){
int i = rand()%26;
cout << d[i] << " ";
y.pb(i);
}
cout << endl;
string s, ns;
while(sz(s) < C){
cin >> ns;
s += ns;
}
rep(ci,C) if(y[ci] == fix(s[ci])-'A') point++;
}
tot = SET*C;
printf("Correct : %d / %d\n",point,tot);
int tm = nowTime();
printf("Time : %.3fs + %d * 3s = %.3fs\n", tm*0.001, tot-point, (tot-point)*3+tm*0.001);
} else if(mode == 3) {
rep(si,SET){
vi y;
string s;
rep(ci,C){
int i = rand()%26;
s += i+'a';
y.pb(i);
}
cout << s << endl;
rep(ci,C){
cin >> s;
if(s == d[y[ci]]) point++;
}
}
tot = SET*C;
printf("Correct : %d / %d\n",point,tot);
int tm = nowTime();
printf("Time : %.3fs + %d * 3s = %.3fs\n", tm*0.001, tot-point, (tot-point)*3+tm*0.001);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment