#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<corecrt.h>
void help()
{
printf("\n******************************************");
printf("\n**********输入过程中无法退出操作**********");
printf("\n**********请按所给字母敲击键盘************");
printf("\n**请按任意键开始测试,按下首字母开始计时**");
printf("\n**********输入出错请以任意键结束**********");
printf("\n****************************************** ");
printf("\n\n");
}
int main()
{
char ch;
char str[51] = "";
int i=0;
int count;
time_t start_time=0, end_time=0;
int waste_time;
while (1)
{
system("cls");
help();
ch = _getch();
if (i == 0)
{
start_time = time(NULL);
}
srand((unsigned)time(NULL));
for (i = 0; i < 50; i++)
{
str[i] = rand() % 26 + 'a';
}
str[50] = '\0';
printf("%s\n", str);
count = 0;
for (i = 0; i < 50; i++)
{
ch = _getch();
if (ch == str[i])
{
count++;
printf("%c", ch);
}
else
{
printf("_");
}
}
end_time = time(NULL);
waste_time = end_time - start_time;
printf("\ncount=%d\n", count);
printf("正确率为:%d%c\n", count * 100 / 50, '%');
printf("总共消耗的时间为%lld秒\n", (long long int)waste_time);
while (1)
{
ch = _getch();
if (ch == ' ')
break;
if (ch == 27)
return 0;
}
}
return 0;
}
04-22
535
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-14
1017
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-28