Guest User

Untitled

a guest
Jan 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. /*
  2. 學號:499261057
  3. 姓名:林忠萱
  4. 班級:資工一甲
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9.  
  10. int main()
  11. {
  12. int num;
  13. srand(time(NULL));
  14. printf("請選擇難度:(1)normal(不重複數字);(2)Difficult(重複數字) [輸入 1 or 2 ]");
  15. scanf("%d",&num);
  16. int a1, b1, c1, d1;
  17. if( num == 1)
  18. {
  19. int countA=0,countB=0,total=0;
  20. int a = (rand() % 10);
  21. int b = (rand() % 10);
  22. int c = (rand() % 10);
  23. int d = (rand() % 10);
  24. while (a==b || a==c || a==d || b==c || c==d || b==d)
  25. {
  26. int a = (rand() % 10);
  27. int b = (rand() % 10);
  28. int c = (rand() % 10);
  29. int d = (rand() % 10);
  30. }
  31.  
  32. printf("請輸入四個0~9數字[不重覆之數字][中間需有空白]:");
  33. scanf("%d %d %d %d", &a1, &b1, &c1, &d1);
  34.  
  35. if (a1==b || a1==c || a1==d)
  36. countB++;
  37. if (b1==a || b1==c || b1==d)
  38. countB++;
  39. if (c1==a || c1==b || c1==d)
  40. countB++;
  41. if (d1==a || d1==b ||d1==c)
  42. countB++;
  43.  
  44. if(a1==a)
  45. countB++;
  46. if(b1==b)
  47. countB++;
  48. if(c1==c)
  49. countA++;
  50. if(d1==d)
  51. countA++;
  52. total++;
  53. printf("%dA%dB\n",countA,countB);
  54. printf("恭喜答對! , 共花了: %d次機會\n",total);
  55. }
  56.  
  57. else if( num == 2)
  58. {
  59. int countA=0,countB=0,total=0;
  60. int a = (rand() % 10);
  61. int b = (rand() % 10);
  62. int c = (rand() % 10);
  63. int d = (rand() % 10);
  64. printf("請輸入四個0~9數字[重複數字][中間需有空白]:");
  65. scanf("%d %d %d %d", &a1, &b1, &c1, &d1);
  66.  
  67. if (a1==b || a1==c || a1==d)
  68. countB++;
  69. if (b1==a || b1==c || b1==d)
  70. countB++;
  71. if (c1==a || c1==b || c1==d)
  72. countB++;
  73. if (d1==a || d1==b ||d1==c)
  74. countB++;
  75.  
  76. if(a1==a)
  77. countB++;
  78. if(b1==b)
  79. countB++;
  80. if(c1==c)
  81. countA++;
  82. if(d1==d)
  83. countA++;
  84. total++;
  85. printf("%dA%dB\n",countA,countB);
  86. printf("恭喜答對! , 共花了: %d次機會\n",total);
  87. }
  88. system("PAUSE");
  89. return 0;
  90. }
Add Comment
Please, Sign In to add comment