写了个唐诗组合任务小程序,有兴趣大家研究一下。
先上代码:程序代码:
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <windows.h> struct TIME { int hour, minute, second; void count_down(); void time_show(); void time_run(); void time_set(int, int, int); }; void poem_store(); void poem_show(char letter, char a[10]); int main(void) { char array[10], check[2]; char letter; int h = 0, m = 0, s = 2; int i, j = 2, score = 0; printf("请在5分钟内完成唐诗组合任务!\n"); TIME a; a.time_set(h, m, s); a.time_run(); printf("\n"); poem_store(); printf("\n请用上面诗句对应的大写字母组织两个五言绝句:"); while(j--) { printf("\n请输入四个大写字母,用空格间隔后回车:\n"); for (i = 0; i < 4 && EOF != scanf(" %c", &letter); i++) { poem_show(letter, array); } array[i] = 0; check[j] = array[0]; if (strcmp(array,"star") == 0 || strcmp(array, "foug") == 0) { if (check[1] == check[0]) printf("重复组合,得0分!\n"); else { score += 15; printf("你太厉害了,再接再厉!现在的分数是%d\n", score); } } else printf("错误!得0分.\n"); } printf("稍等片刻……\n"); Sleep(3000); system("cls"); poem_store(); printf("\n请用上面诗句对应的大写字母组织一个五言律诗:"); printf("\n请输入八个大写字母,用空格间隔后回车:"); for (i = 0; i < 8 && EOF != scanf(" %c", &letter); i++) { poem_show(letter, array); } array[i] = 0; if (strcmp(array,"bmecknyz") == 0 ) { score += 30; printf("你太厉害了,再接再厉!现在的分数是%d\n", score); } else printf("错误!得0分.\n"); printf("稍等片刻……\n"); Sleep(3000); system("cls"); poem_store(); printf("\n请用上面诗句对应的大写字母组织一个五言乐府:"); printf("\n请输入十个大写字母,用空格间隔后回车:"); for (i = 0; i < 10 && EOF != scanf(" %c", &letter); i++) { poem_show(letter, array); } array[i] = 0; if (strcmp(array,"wjhpdilqvx") == 0 ) { score += 40; printf("你太厉害了!现在的分数是%d\n", score); } else printf("错误!得0分.\n"); if (h == 0 && m == 0 && s == 0) { printf("时间到!你的成绩是%d分\n", score); Sleep(3000); exit(0); } return 0; } void poem_store() { printf("A:本来无一物B:百川东到海C:常恐秋节至D:荡胸生层云E:何处惹尘埃\n"); printf("F:两句三年得G:归卧故山丘H:何时复西归I:岱宗夫如何J:决眦入归鸟\n"); printf("K:焜黄华叶衰L:老大徒伤悲M:明镜亦非台N:一吟双泪流O:知音如不赏\n"); printf("P:菩提本无树Q:青青园中葵R:齐鲁青未了S:少壮不努力T:造化钟神秀\n"); printf("U:会当凌绝顶V:一览众山小W:万物生光辉X:阴阳割昏晓Y:阳春布德泽Z:朝露待日晞\n"); } void poem_show(char letter, char a[10]) { switch (letter) { case 'A': printf("本来无一物\n"); a[2] = 'a'; break; case 'B': printf("百川东到海\n"); a[6] = 'l'; break; case 'C': printf("常恐秋节至\n"); a[4] = 'd'; break; case 'D': printf("荡胸生层云\n"); a[4] = 'k'; break; case 'E': printf("何处惹尘埃\n"); a[3] = 'r'; break; case 'F': printf("两句三年得\n"); a[0] = 'f'; break; case 'G': printf("归卧故山丘\n"); a[3] = 'g'; break; case 'H': printf("何时复西归\n"); a[7] = 'q'; break; case 'I': printf("岱宗夫如何\n"); a[0] = 'b'; break; case 'J': printf("决眦入归鸟\n"); a[5] = 'n'; break; case 'K': printf("焜黄华叶衰\n"); a[5] = 'i'; break; case 'L': printf("老大徒伤悲\n"); a[9] = 'x'; break; case 'M': printf("明镜亦非台\n"); a[1] = 't'; break; case 'N': printf("一吟双泪流\n"); a[1] = 'o'; break; case 'O': printf("知音如不赏\n"); a[2] = 'u'; break; case 'P': printf("菩提本无树\n"); a[0] = 's'; break; case 'Q': printf("青青园中葵\n"); a[0] = 'w'; break; case 'R': printf("齐鲁青未了\n"); a[1] = 'm'; break; case 'S': printf("少壮不努力\n"); a[8] = 'v'; break; case 'T': printf("造化钟神秀\n"); a[2] = 'e'; break; case 'U': printf("会当凌绝顶\n"); a[6] = 'y'; break; case 'V': printf("一览众山小\n"); a[7] = 'z'; break; case 'W': printf("万物生光辉\n"); a[3] = 'p'; break; case 'X': printf("阴阳割昏晓\n"); a[3] = 'c'; break; case 'Y': printf("阳春布德泽\n"); a[2] = 'h'; break; case 'Z': printf("朝露待日晞\n"); a[1] = 'j'; break; default: printf("哦米拖佛,施主请输入大写字母\n"); break; } } void TIME::count_down() { long t = time(NULL); while (t == time(NULL)); if (--second < 0) { second = 59; if (--minute < 0) { minute = 59; --hour; } } } void TIME::time_show() { printf("\r"); if (hour < 10) printf("0"); printf("%d:", hour); if (minute < 10) printf("0"); printf("%d:", minute); if (second < 10) printf("0"); printf("%d", second); } void TIME::time_run() { while (second != 0 || minute != 0 || hour != 0) { count_down(); time_show(); } } void TIME::time_set(int h, int m, int s) { hour = h; minute = m; second = s; }
我本来的愿望是通过一个倒计时器去限制任务的时间,但是我的计时器无法与人员操作同步,貌似要把倒计时器的规定时间显示完了后 才能进入唐诗组合任务界面, 有什么办法边做任务边计时,然后到了规定时间(5分钟)必须交卷!
[ 本帖最后由 有容就大 于 2012-2-4 17:49 编辑 ]