質問編集履歴
1
プログラムを書き換えました
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,162 +14,128 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
int main(void){
|
17
|
+
int main(void) {
|
18
|
+
|
19
|
+
int a = 0, b = 0;
|
20
|
+
|
21
|
+
int points_a = 0;
|
22
|
+
|
23
|
+
int points_b = 0;
|
24
|
+
|
25
|
+
int turns = 0;
|
26
|
+
|
27
|
+
char inputs[][10] = { "Rock","Scissors","Paper" };
|
18
28
|
|
19
29
|
|
20
30
|
|
21
|
-
|
31
|
+
for (turns = 0; turns < 10; turns++) {
|
22
32
|
|
33
|
+
while (1) {
|
34
|
+
|
35
|
+
printf("Input for game number %d: ", turns + 1);
|
36
|
+
|
37
|
+
scanf("%d %d", &a, &b);
|
38
|
+
|
39
|
+
if (a < 1 || a>3 || b < 1 || b>3)
|
40
|
+
|
41
|
+
printf("Invalid input(Rock:1,Scissors:2,Paper:3),please try again:\n\n");
|
42
|
+
|
43
|
+
else
|
44
|
+
|
23
|
-
|
45
|
+
break;
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
printf("A plays %s,B plays %s: ", inputs[a - 1], inputs[b - 1]);
|
24
50
|
|
25
51
|
|
26
52
|
|
27
|
-
|
53
|
+
if (a == b) {
|
28
54
|
|
29
|
-
printf("
|
55
|
+
printf("draw.\n");
|
30
56
|
|
31
|
-
|
57
|
+
}
|
32
58
|
|
33
|
-
|
59
|
+
else if ((a == 1 && b == 2) || (a == 2 && b == 1)) {
|
34
60
|
|
35
|
-
if
|
61
|
+
printf("%c wins and gets 1points.\n", (a < b ? 'A' : 'B'));
|
36
62
|
|
63
|
+
if (a < b)
|
64
|
+
|
65
|
+
points_a += 1;
|
66
|
+
|
67
|
+
else
|
68
|
+
|
69
|
+
points_b += 1;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
else if ((a == 1 && b == 3) || (a == 3 && b == 1)) {
|
76
|
+
|
77
|
+
printf("%c wins and gets 5 points.\n", (a > b ? 'A' : 'B'));
|
78
|
+
|
79
|
+
if (a > b)
|
80
|
+
|
81
|
+
points_a = 5;
|
82
|
+
|
83
|
+
else
|
84
|
+
|
85
|
+
points_b = 5;
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
else if ((a == 2 && b == 3) || (a == 3 && b == 2)) {
|
90
|
+
|
91
|
+
printf("%c wins and gets 2 points.\n", (a < b ? 'A' : 'B'));
|
92
|
+
|
93
|
+
if (a > b)
|
94
|
+
|
95
|
+
points_a += 2;
|
96
|
+
|
97
|
+
else
|
98
|
+
|
99
|
+
points_b += 2;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
else {
|
104
|
+
|
105
|
+
printf("Unknown error\n");
|
106
|
+
|
107
|
+
return -1;
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
printf("Current number of points: A - %d, B - %d. \n\n", points_a, points_b);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
if (points_a >= 21 || points_b >= 21)
|
118
|
+
|
37
|
-
break;
|
119
|
+
break;
|
38
120
|
|
39
121
|
}
|
40
122
|
|
41
|
-
|
123
|
+
if (points_a == points_b) {
|
42
124
|
|
43
|
-
|
44
|
-
|
45
|
-
printf("
|
125
|
+
printf("Draw(points:A %d,B %d)\n", points_a, points_b);
|
46
|
-
|
47
|
-
|
48
126
|
|
49
127
|
}
|
50
128
|
|
129
|
+
else {
|
51
130
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
switch (a) {
|
56
|
-
|
57
|
-
case 1:
|
58
|
-
|
59
|
-
printf("A: Rock,");
|
60
|
-
|
61
|
-
break;
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
case 2:
|
66
|
-
|
67
|
-
printf("
|
131
|
+
printf("\nWinner: %c (points: A %d, B %d)\n", (points_a > points_b) ? 'A' : 'B', points_a, points_b);
|
68
|
-
|
69
|
-
break;
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
case 3:
|
74
|
-
|
75
|
-
printf("A: Paper,");
|
76
|
-
|
77
|
-
break;
|
78
132
|
|
79
133
|
}
|
80
|
-
|
81
|
-
switch (b) {
|
82
|
-
|
83
|
-
case 1:
|
84
|
-
|
85
|
-
printf(" B: Rock;");
|
86
|
-
|
87
|
-
break;
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
case 2:
|
92
|
-
|
93
|
-
printf(" B: Scissors;");
|
94
|
-
|
95
|
-
break;
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
case 3:
|
100
|
-
|
101
|
-
printf(" B: Paper;");
|
102
|
-
|
103
|
-
break;
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
if (a == b) {
|
110
|
-
|
111
|
-
printf("Draw (points: A 0, B 0)\n");
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
else if (a == 1 && b == 2) {
|
118
|
-
|
119
|
-
printf(" A wins and gets 1 points.\n");
|
120
|
-
|
121
|
-
printf("Winner: A (points: A 1, B 0)\n");
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
else if (a == 2 && b == 3) {
|
126
|
-
|
127
|
-
printf(" A wins and gets 2 points.\n");
|
128
|
-
|
129
|
-
printf("Winner: A (points: A 2, B 0)\n");
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
else if (a == 3 && b == 1) {
|
134
|
-
|
135
|
-
printf(" A wins and gets 5 points.\n");
|
136
|
-
|
137
|
-
printf("Winner: A (points: A 5, B 0)\n");
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
else if (a == 1 && b == 3) {
|
144
|
-
|
145
|
-
printf(" B wins and gets 1 points.\n");
|
146
|
-
|
147
|
-
printf("Winner: B (points: A 0, B 5)\n");
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
else if (a == 2 && b == 1) {
|
152
|
-
|
153
|
-
printf(" B wins and gets 1 points.\n");
|
154
|
-
|
155
|
-
printf("Winner: B (points: A 0, B 1)\n");
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
else if (a == 3 && b == 2) {
|
160
|
-
|
161
|
-
printf(" B wins and gets 2 points.\n");
|
162
|
-
|
163
|
-
printf("Winner: B (points: A 0, B 2)\n");
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
134
|
|
171
135
|
return(0);
|
172
136
|
|
173
137
|
}
|
174
138
|
|
139
|
+
|
140
|
+
|
175
141
|
```
|