-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (69 loc) · 1.76 KB
/
Copy pathmain.cpp
File metadata and controls
84 lines (69 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef string Ja;
typedef string En;
typedef map<Ja,En> Dict;
typedef vector<Dict> Dicts;
vector<std::string> split(const std::string &str, char sep);
map<string, string> analyze_file(string str);
// 無理やり導入したクラス
// mapをメンバ変数として持つだけ
class Dictionary {
public:
Dict dict;
// StringからDictを作る
Dictionary(string str) {
vector<string> v = split(str, ':');
En en = v[0];
Ja ja = v[1];
dict[en] = ja;
}
// 正解かどうかチェックする
void answer() {
for(auto itr = dict.begin(); itr != dict.end(); ++itr) {
cout << itr->second<< "の英語は?";
string answer;
cin >> answer;
if(answer == itr->first)
cout << "正解\n";
else
cout << "不正解\n";
}
}
};
int main(int argc,char *argv[]) {
string filename = argv[1];
std::ifstream ifs(filename);
std::string str;
if (ifs.fail()) {
std::cerr << "Failed: load file" << std::endl;
return -1;
}
vector<Dictionary> dicts;
while (getline(ifs, str)) {
dicts.push_back(Dictionary(str));
}
for(auto dict = dicts.rbegin(); dict != dicts.rend(); ++dict) {
dict->answer();
}
cout << "おつおつ!\n";
}
// stringにsplitがないらしいので作成
vector<std::string> split(const std::string &str, char sep) {
std::vector<std::string> v;
auto first = str.begin();
while( first != str.end() ) {
auto last = first;
while( last != str.end() && *last != sep )
++last;
v.push_back(std::string(first, last));
if( last != str.end() )
++last;
first = last;
}
return v;
}