fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <time.h>
  5. #include <ctype.h>
  6. #define RANDOM(MIN,MAX) ((MIN)+(int)(rand()/(float)RAND_MAX*((MAX)-(MIN)+1)))
  7. int winner(int[],int);
  8. void disp(int[],int);
  9. char ntoc(int);
  10.  
  11. int main(void)
  12. {
  13. char c;
  14. int a[3];
  15. // srand((unsigned int) time(NULL));
  16.  
  17. puts("じゃんけんぽん!!");
  18. puts("(グー = g/G、チョキ = v/V、 パー = w/W)");
  19. while(1)
  20. {
  21. c = getch();
  22. if(isupper(c)) c += 0x20;
  23. printf("%c\n",c);
  24. switch(c)
  25. {
  26. case 'g': a[0] = 1; break;
  27. case 'v': a[0] = 2; break;
  28. case 'w': a[0] = 3; break;
  29. default: a[0] = 0;
  30. }
  31.  
  32. for(int i = 1; i < 3; i++) a[i] = RANDOM(1, 3);
  33.  
  34. switch(winner(a,3))
  35. {
  36. case 1:
  37. if(c == 'g')
  38. {
  39. disp(a,3);
  40. puts("You Win!!");
  41. return 0;
  42. }
  43. else
  44. {
  45. disp(a,3);
  46. puts("You Lose...");
  47. return -1;
  48. }
  49. break;
  50. case 2:
  51. if(c == 'v')
  52. {
  53. disp(a,3);
  54. puts("You Win!!");
  55. return 0;
  56. }
  57. else
  58. {
  59. disp(a,3);
  60. puts("You Lose...");
  61. return -1;
  62. }
  63. break;
  64. case 3:
  65. if(c == 'w')
  66. {
  67. disp(a,3);
  68. puts("You Win!!");
  69. return 0;
  70. }
  71. else
  72. {
  73. disp(a,3);
  74. puts("You Lose...");
  75. return -1;
  76. }
  77. default:
  78. }
  79. disp(a,3);
  80. puts("あいこでしょ!!");
  81. }
  82. return 0;
  83. }
  84.  
  85. int winner(int a[],int n)
  86. {
  87. int g,w,v;
  88. g = w = v = 0;
  89.  
  90. for(int i = 0;i < n;i++)
  91. {
  92. switch(a[i])
  93. {
  94. case 1:
  95. g++;
  96. break;
  97. case 2:
  98. v++;
  99. break;
  100. case 3:
  101. w++;
  102. break;
  103. default:
  104. }
  105. }
  106. if(a[0] == 0) return 0;
  107. if(g > 0 && v > 0 && w == 0) return 1;
  108. if(g > 0 && w > 0 && v == 0) return 3;
  109. if(v > 0 && w > 0 && g == 0) return 2;
  110. return 0;
  111. }
  112.  
  113. void disp(int a[],int n)
  114. {
  115. printf("(あなた:%c ,",ntoc(a[0]));
  116. for(int i = 1;i < n;i++) printf("PC%d:%c ,",i,ntoc(a[i]));
  117. puts("\b\b)");
  118. }
  119.  
  120. char ntoc(int n)
  121. {
  122. switch(n)
  123. {
  124. case 1: return 'g';
  125. case 2: return 'v';
  126. case 3: return 'w';
  127. default: return '?';
  128. }
  129. return '?';
  130. }
  131.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:10: fatal error: 'conio.h' file not found
#include <conio.h>
         ^~~~~~~~~
1 error generated.
stdout
Standard output is empty