UID1636475性别保密经验 EP铁粒 粒回帖0主题精华在线时间 小时注册时间2024-2-28最后登录1970-1-1
| - #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <time.h>
- #include <string.h>
- #define cls() system("cls")
- int rand2(int max,clock_t c) {
- int i=0;
- for(; (i=rand())>max;);
- return i;
- }
- int main(void) {
- clock_t m = clock();
- char *str,*ans;
- unsigned int level=1,i;
- printf("记忆游戏! 按回车键开始");
- getchar();
- cls();
- str=(char*)malloc(sizeof(char)*4);
- ans=(char*)malloc(sizeof(char)*4);
- for(;;) {
- m = clock();
- srand(m);
- for(i=0; i<level+2; i++) {
- //printf("%lu",(unsigned long int)m)
- if(rand2(1,m)) str[i]='a';
- else str[i]='b';
- }
- str[level+2]='\0';
- printf(str);
- //getchar();
- Sleep(5000);
- cls();
- scanf("%s",ans);
- //printf("%s %s",str,ans);
- if(!strcmp(str,ans)){
- level++;
- printf("正确!你的等级为%u",level);
- Sleep(2000);
- cls();
- }else{
- printf("\nOh no,错误了哦,您的等级是%u",level);
- getchar();
- return 0;
- }
- str=(char*)realloc(str,sizeof(char)*(level+3));
- ans=(char*)realloc(ans,sizeof(char)*(level+3));
- }
- return 0;
- }
复制代码
用最最基础的C++系统编得,适合初学者模仿。
*:此文件以CC-BY-4.0协议发布
|
|