简易打字测试
功能:(1)三種LEVEL;(2)根據LEVEL選擇計時;(3)隨機選擇文章;(4)顯示打字能力,并判斷是否通關
待解決問題:提前打完了怎么辦?
//打字游戲#include <stdio.h> #include <time.h> #include <stdlib.h> #include <string.h>int choose(char passage[][1000]);//隨機選文函數 int counttime(int t);//計時函數 int piont(char *passage,char *answer,int t,int *letter,int *speed,int *correct,int *total);//統分函數int main(void) {char passage[3][1000]={" Once when I was six years old I saw a magnificent picture in a book, called True Stories from Nature, about the primeval forest. It was a picture of a boa constrictor in the act of swallowing an animal. Here is a copy of the drawing. In the book it said, Boa constrictors swallow their prey whole, without chewing it."," My drawing was not a picture of a hat. It was a picture of a boa constrictor digesting an elephant. But since the grown-ups were not able to understand it, I made another drawing: I drew the inside of the boa constrictor, so that the grown-ups could see it clearly. They always need to have things explained. My Drawing Number Two looked like this: The grown-ups response, this time was to advise me to lay aside my drawings of boa constrictors, whether from the inside or the outside, and devote myself instead to geography, history, arithmetic and grammar."," That is why, at the age of six, I gave up what might have been a magnificent career as a painter. I had been disheartened by the failure of my Drawing Number One and my Drawing Number Two. Grown-ups never understand anything by themselves, and it is tiresome for children to be always and forever explaining things to them."};char answer[500];int total,letter,speed,correct,level,which,t[3]={180,120,60}; // total文章總字數,letter輸入的總字數,speed輸詞速度(只計算準確的量),correct正確字數,level選擇級別,which抽中文章,t總計時printf("Easy1, Medium2, Hard3?\n");scanf("%d",&level);which = choose(passage);counttime(t[level-1]);gets(answer);piont(passage[which],answer,t[level-1],&letter,&speed,&correct,&total);printf("Level %d\n\ In %d seconds, you had printed %d letters, in which %d one are correct.\nYour speed is %d letter/min.\n",level,t[level-1],letter,correct,speed);if (correct > total*8/10){printf("You passed level %d!\n",level);}elseprintf("Fail the challenge!\n");return 0; }int choose(char passage[][1000]) {int i;srand((unsigned)time(NULL));i = rand()%3;printf("%s\n",passage[i]);printf("\n");return i; }int counttime(int t) {long a,b;printf("Start now?\n");getchar();getchar();printf("Start!\n");a = time(NULL);while (1){b = time(NULL);if ((b-a)>=t){printf("\n%d seconds off!\n",t);break;}}return 0; }int piont(char *passage,char *answer,int t,int *letter,int *speed,int *correct,int *total) {int i;*correct = 0;for (i=0; passage[i] != '\0'; i++){;}*total = i;for (i=0; answer[i] != 0; i++){if (passage[i] == answer[i]){(*correct)++;}}*letter = i;*speed = (*correct)*60/t;return 0; }
選文摘自The Little Prince
?
?
?
總結
- 上一篇: 在Windows 7 Media Cen
- 下一篇: 文献记录(part109)--Self-