蒟蒻做的打字游戏
  • 板块灌水区
  • 楼主houpingze
  • 当前回复13
  • 已保存回复13
  • 发布时间2020/6/21 19:57
  • 上次更新2023/11/7 00:15:02
查看原帖
蒟蒻做的打字游戏
253765
houpingze楼主2020/6/21 19:57
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int n,cnt,m;
void RandStr(vector<char>&vec, const int len)
{
    srand((int)time(0)); 
    char temp;
    for (int i = 0; i < len; i++){
        switch (rand()%3)
        {
            case 0:
                temp= rand()%10 + '0';   
                break;

            case 1:
                temp = rand()%26 + 'a';
                break;

            case 2:
                temp = rand()%26 + 'A';
                break;
        }
        vec.push_back(temp);
    } 
}
clock_t start,end;
int main(){
	vector<char>vec;
	cout<<"欢迎来到打字游戏~\n您要打长度为多少的字符串?\n";
	cin>>n;
	RandStr(vec, n);
	string s,daan="";
	cout<<"/n好,打字开始!\n";
	for (int i=0;i<n;i++) {
        cout << vec[i];
        daan+=vec[i];
    }
    cout<<endl;
    start=clock();
	cin>>s;
	end=clock();
	double endtime=(double)(end-start)/CLOCKS_PER_SEC;
	double e=(double)(end-start)/CLOCKS_PER_SEC/s.size();
	cout<<"\n您用了"<<endtime<<"秒\n平均每个字母/数字用了"<<e<<"秒\n";
	if(s!=daan){
		cout<<"ERROR!打字错误!";
		Sleep(3000);
		system("CLS");
		return main();
	}else {
		cout<<"恭喜~打字全对~";
		Sleep(2000);
		system("CLS");
		return main();
	}
}

2020/6/21 19:57
加载中...