#3
by かずま » 5年前
次のプログラムは参考になりますか?
コード:
#include <iostream> // cin, cout
#include <string> // string
#include <ctime> // time
#include <cstdlib> // rand, srand
using namespace std;
struct Answer {
string hurigana;
string romazi;
};
Answer answer[] = {
{ "きゅうり", "kyuuri" },
{ "レタス", "retasu" },
{ "トマト", "tomato" },
{ "にんじん", "ninjin" },
{ "じゃがいも", "jagaimo" },
};
const int N = sizeof(answer) / sizeof(answer[0]);
const int LIMIT = 15;
int main()
{
int index[N], n = N, miss = 0, t;
time_t t0 = time(0);
srand(t0);
for (int i = 0; i < N; i++) index[i] = i;
while (n > 0 && (t = time(0) - t0) < LIMIT) {
int k = rand() % n, i = index[k];
index[k] = index[--n];
cout << answer[i].hurigana << endl;
while ((t = time(0) - t0) < LIMIT) {
string nyuuryoku;
cin >> nyuuryoku;
if (nyuuryoku == answer[i].romazi) break;
miss++;
cout << " wrong! again: " << answer[i].hurigana << endl;
}
}
cout << t << " sec passed\n" << "you made " << miss << " mistakes\n";
}
次のプログラムは参考になりますか?
[code]
#include <iostream> // cin, cout
#include <string> // string
#include <ctime> // time
#include <cstdlib> // rand, srand
using namespace std;
struct Answer {
string hurigana;
string romazi;
};
Answer answer[] = {
{ "きゅうり", "kyuuri" },
{ "レタス", "retasu" },
{ "トマト", "tomato" },
{ "にんじん", "ninjin" },
{ "じゃがいも", "jagaimo" },
};
const int N = sizeof(answer) / sizeof(answer[0]);
const int LIMIT = 15;
int main()
{
int index[N], n = N, miss = 0, t;
time_t t0 = time(0);
srand(t0);
for (int i = 0; i < N; i++) index[i] = i;
while (n > 0 && (t = time(0) - t0) < LIMIT) {
int k = rand() % n, i = index[k];
index[k] = index[--n];
cout << answer[i].hurigana << endl;
while ((t = time(0) - t0) < LIMIT) {
string nyuuryoku;
cin >> nyuuryoku;
if (nyuuryoku == answer[i].romazi) break;
miss++;
cout << " wrong! again: " << answer[i].hurigana << endl;
}
}
cout << t << " sec passed\n" << "you made " << miss << " mistakes\n";
}
[/code]