#include <stdio.h>
#include <stdlib.h>
#include <time.h>int main()
{// 设置随机数种子srand((unsigned int)time(NULL));char c[20+1] = { 0 }; // 加上一个 \0结束符位置// 产生随机数for (int i = 0; i < 20; i++){c[i] = rand() % 26 + 'a';}printf("%s\n", c);int count = 0; //正确输入// 用户输入,并判断for (int i = 0; i < 20; i++){char ch = _getch(); // 输入就检测if (ch == c[i]){printf("%c", ch);count++;}else{printf("_");}}printf("\n");// 正确率/*double s = (double)count / 20 * 100;printf("正确率为:%.2lf%%", s);*/printf("正确率为:%.2lf%%", (double)count / 20 * 100);system("pause");return EXIT_SUCCESS;
}