C++小游戏-1-1.0

· · 个人记录

训练记忆力

#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int szgs, jgms; string s, t;
int main() {
    srand(time(0));
    system("color 0F");
    cout << "Please input how many numbers:";
    cin >> szgs;
    if (szgs <= 5) szgs = 5;
    cout << "Please input how many metrosecond(ms):";
    cin >> jgms;
    if (jgms >= 1000) jgms = 1000;
    if (jgms <= 5) jgms = 5;
    for (int i = 1, j = 1, k = 0; j <= szgs; i *= rand(), i %= 10, j++, k = (i * rand() + rand()) % 10) {
        cout << k;
        s += (char)(k + '0');
        Sleep(jgms);
    }
    system("cls");
    cout << "Please input that string:(the length is:" << szgs << ")\n";
    cin >> t;
    int wrong = 0;
    for (int i = 0; i < szgs; i++) if (s[i] != t[i]) wrong++;
    system("cls");
    if (!wrong) cout << "SSS", system("color 6F");
    else if (wrong == 1) cout << "S", system("color EF");
    else if (wrong <= 3) cout << "A", system("color 5F");
    else if (wrong <= 5) cout << "B", system("color 4F");
    else if (wrong <= 10) cout << "C", system("color 2F");
    else cout << "D", system("color 1F");
    cout << "\nwrong:" << wrong;
    if (wrong) cout << "\nthe answer is:" << s;
    return 0;
}

有点短,持续更新中