Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 學號:499261057
- 姓名:林忠萱
- 班級:資工一甲
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- int num;
- srand(time(NULL));
- printf("請選擇難度:(1)normal(不重複數字);(2)Difficult(重複數字) [輸入 1 or 2 ]");
- scanf("%d",&num);
- int a1, b1, c1, d1;
- if( num == 1)
- {
- int countA=0,countB=0,total=0;
- int a = (rand() % 10);
- int b = (rand() % 10);
- int c = (rand() % 10);
- int d = (rand() % 10);
- while (a==b || a==c || a==d || b==c || c==d || b==d)
- {
- int a = (rand() % 10);
- int b = (rand() % 10);
- int c = (rand() % 10);
- int d = (rand() % 10);
- }
- printf("請輸入四個0~9數字[不重覆之數字][中間需有空白]:");
- scanf("%d %d %d %d", &a1, &b1, &c1, &d1);
- if (a1==b || a1==c || a1==d)
- countB++;
- if (b1==a || b1==c || b1==d)
- countB++;
- if (c1==a || c1==b || c1==d)
- countB++;
- if (d1==a || d1==b ||d1==c)
- countB++;
- if(a1==a)
- countB++;
- if(b1==b)
- countB++;
- if(c1==c)
- countA++;
- if(d1==d)
- countA++;
- total++;
- printf("%dA%dB\n",countA,countB);
- printf("恭喜答對! , 共花了: %d次機會\n",total);
- }
- else if( num == 2)
- {
- int countA=0,countB=0,total=0;
- int a = (rand() % 10);
- int b = (rand() % 10);
- int c = (rand() % 10);
- int d = (rand() % 10);
- printf("請輸入四個0~9數字[重複數字][中間需有空白]:");
- scanf("%d %d %d %d", &a1, &b1, &c1, &d1);
- if (a1==b || a1==c || a1==d)
- countB++;
- if (b1==a || b1==c || b1==d)
- countB++;
- if (c1==a || c1==b || c1==d)
- countB++;
- if (d1==a || d1==b ||d1==c)
- countB++;
- if(a1==a)
- countB++;
- if(b1==b)
- countB++;
- if(c1==c)
- countA++;
- if(d1==d)
- countA++;
- total++;
- printf("%dA%dB\n",countA,countB);
- printf("恭喜答對! , 共花了: %d次機會\n",total);
- }
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment