Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <fstream>
- #include <conio.h>
- #include <windows.h>
- #include <time.h>
- #include <string>
- using namespace std;
- float liter(int n, string name)
- {
- clock_t start, end;
- int t, key;
- char k;
- float tm = 0;
- for (int i=0; i < n; i++)
- {
- system("cls");
- cout << "* Игра \"Нажми клавишу\" *\nИграет: " << name;
- cout << "\nОсталось букв: " << n - i << endl;
- t = 192 + rand() % 32;
- k = (char)t;
- cout << "\n Нажмите букву: " << k << endl;
- start = clock();
- while (1)
- {
- key = _getch();
- if (key == t || key - 32 == t)
- {
- end = clock();
- tm += (float(end - start)) / CLOCKS_PER_SEC;
- break;
- }
- }
- }
- return tm;
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- srand(time(0));
- int i, j, n;
- float tm = 0, top[5];
- string name, top_name[5];
- do{
- system("cls");
- cout << " Игра \"Нажми клавишу\"";
- ifstream in("res.txt");
- i = 0;
- cout << "\n\nНаилучшие результаты:\n\n<Имя> <Результат>\n " << endl;
- while (!in.eof() && i < 5)
- {
- in >> top_name[i] >> top[i];
- cout << top_name[i] << "\t" << top[i] << endl;
- i++;
- }
- in.close();
- cout << "\n\nВведите имя: ";
- cin >> name;
- do{
- cout << "Количество букв (10-50): ";
- cin >> n;
- } while (n<10 || n>50);
- tm = liter(n, name);
- system("cls");
- cout << "* Игра \"Нажми клавишу\" *\nИграет: " << name;
- cout << "\n\nИгра окончена\nВаше среднее время: " << tm / n << endl;
- for (i = 0; i < 5; i++)
- if (top[i] > tm / n) break;
- if (i < 5)
- {
- for (j = 4; j>i; j--)
- {
- top[j] = top[j - 1];
- top_name[j] = top_name[j - 1];
- }
- top[i] = tm / n;
- top_name[i] = name;
- }
- ofstream file("res.txt");
- file.clear();
- cout << "\n\nНаилучшие результаты:\n\n<Имя> <Результат>\n" << endl;
- for (i = 0; i < 5; i++)
- {
- file << top_name[i] << ' ' << top[i] << endl;
- cout << top_name[i] << "\t" << top[i] << endl;
- }
- file.close();
- cout << "Сыграть еще раз нажмите SPACE";
- n = _getch();
- } while (n == 32);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement