#include <stdlib.h> #include<stdio.h> #include<time.h> #define N 20
struct tm * GetTime( time_t *t) { struct tm * loctm; time (t); loctm = localtime (t); }
void NewNumber(int *p1, int *p2); int Sum(int a , int b); int Minus(int a , int b); void Judge(int sum,int a,int minus,int b,int *k); int TimeCnt( struct tm *localtime,struct tm begintime); int InTime(struct tm *lt1 ,time_t t , int *pn, int *pk); int AwardLangurage(int *cnt,int *k);
int main(void) {
time_t T; int cnt = 0, k = 0 ; printf(">> %ds时间,准备开始了吗?\n",N); printf(">> 按enter 开始 || 输任意值退出\n",N); if(getchar() == '\n') { struct tm *lt1; struct tm begin; int time; lt1 = GetTime(&T); begin = * lt1; while(1) { time = TimeCnt(lt1,begin); printf(">—————剩余 %ds——————<\t\n",time); if(time >= 0) { InTime(lt1,T,&cnt,&k); }else{ printf(">> 停!时间到!\t\n"); printf(">> 共 %d 题, 答对 %d 题\t\n",cnt,k); switch (AwardLangurage(&cnt,&k)) { case 0: printf("完全正确!你太厉害了!"); break; case 1: printf("优秀!我看好你!"); break; case 2: printf("良好!你很有潜力!"); break; case 3: printf("一般,你需要多练习!"); break; case 4: printf("加油,不要放弃!"); break; case 5: printf("你完美的躲过了正确答案!"); break; case 6: break; default: break; }; printf(">> 按任意键退出\t\n",N); break; } } getchar(); getchar(); } return 0; }
void NewNumber(int *p1, int *p2) { int born ; srand((unsigned)time(NULL)); *p1 = (rand()+2 * rand())%10; *p2 = (rand() * rand()+rand())%10; } int Sum(int a , int b) { int sum; sum = a + b; return sum; }
int Minus(int a , int b) { int minus; if(a < b){ minus = b - a; }else { minus = a - b; } return minus; }
void Judge(int sum,int a,int minus,int b,int *k) {
if(a == sum && b == minus) { printf(" 正确!\n"); *k = *k + 1; }else { printf(" 错误!\n"); } }
int TimeCnt( struct tm *localtime,struct tm begintime) { int minus; if(localtime->tm_min > begintime.tm_min) { minus = localtime->tm_sec + 60 - begintime.tm_sec ; }else { minus = localtime->tm_sec - begintime.tm_sec ; } return (N - minus) ; }
int InTime(struct tm *lt1 ,time_t t , int *pn, int *pk) { int new1, new2, answer1, answer2; int i,sum, begin , minus; NewNumber(&new1,&new2); sum = Sum(new1,new2); minus = Minus(new1,new2); printf(" >> %d +/- %d = ?\t\n",new1 ,new2); *pn = *pn + 1; scanf("%d %d",&answer1, &answer2); Judge(sum,answer1,minus,answer2,pk); lt1 = GetTime(&t); return 0; }
int AwardLangurage(int *cnt,int *k) { int LangurageStand; int error = *cnt - *k ; if(*cnt > 10) { if (error == 0 ) { LangurageStand = 0; }else if(error < (*cnt)/5) { LangurageStand = 1; }else if(error < 2*(*cnt)/5) { LangurageStand = 2; }else if(error < 4*(*cnt)/5) { LangurageStand = 3; }else if(error < *cnt) { LangurageStand = 4; }else { LangurageStand = 5; } }else { if (error == 0 ) { printf("完全正确!你太厉害了!"); }else if(error < *cnt) { printf("还需努力!"); }else { printf("你需要更多练习!"); } LangurageStand = 6; } return LangurageStand; }
|