#include
#include
#include
#include
void main() { int i = 0; int j; time_t t; time_t t_start; time_t t_end; double g_time; int count; //打字个数 int zheng = 0; int cuo = 0; char *p_sr; char *p_s; char *p_t; do{ printf("你想进行几个字母的打字训练,必须是正数/n"); scanf("%d",&count); }while(count<0); printf("现在进行%d个字符的打字游戏/n",count); p_sr=(char *)malloc(count + 1); p_t=(char *)malloc(count); if(NULL==p_sr||NULL==p_t) { printf("分配内存失败!/n"); return NULL; } p_s=p_sr; while(i < count) { srand((unsigned)time(&t)); j=rand()%'z'; //printf("%d/n",j); if((j>='a'&&j<='z')||(j>='A'&&j<='Z')) { *p_s=j; p_s++; i++; } } *p_s='/0'; printf("请输入:%s/n",p_sr); time(&t_start); scanf("%s0/n",p_t); time(&t_end); g_time=difftime(t_end,t_start); printf("打字所用时间为%6.0f秒/n",g_time); p_s=p_sr; while(p_s!='/0') { /* if(!strcmp(*p_t,*p_sr)) printf("打字完全一致/n"); else printf("没有全部正确,要加油啊!/n"); */ if(*p_s==*p_t) zheng++; else cuo++; p_s++; p_t++; } printf("正确率为:%d/%/n",zheng/(zheng+cuo)); free(p_sr); p_sr=NULL; free(p_t); p_t =NULL; return NULL; }
dazi
最新推荐文章于 2021-07-29 05:41:42 发布