类似于金山打字的小游戏

今天信息奥赛课,老师让我们做一道题目。主要是为了了解C语言中的头函数#include<time.h>和#include<conio.h>

time头文件测试时间

conio头文件有新的读入工具

挺好玩的

源代码如下:

#include<stdio.h>
#include<string.h>
#include<time.h>
#include<conio.h>
char s1[101]="Tsinghua University";
int i;
char c;
clock_t t1,t2;
double total,speed;
int main()
{
	puts(s1);
	t1=clock();
	do
	{
		c=getch();
		if(c==13)
		{
			printf("\n");
		}
		else
		{
			if(s1[i]==c)
			  {
			  	printf("%c",c);
			  	i++;
			  }
			  else
			  {
			  	printf("%c",c);
			  }
		}
	}while(c!=13); 
	t2=clock();
	total=t2-t1;
	speed=(i+1)*1000/total;
	printf("正确%d个,速度%lf个/秒",i+1,speed);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/yang_2002/article/details/79651928