两方分别报数 谁先报到30获胜计算机报数原则:若剩下的数除以3余1,报一个数,若余2则报两个数,否则随机报一或两个数。答案下:请问其中的s为什么不是30-s,30-s才是剩余数的个数啊
</>#include<time.h>#include<stdio.h>#include<stdlib.h>int Input(int t);int ControlComputer(int s);int Rnd();
int main(){ int tol = 1;
if (Rnd() == 1) { tol = Input(tol); } while (tol < 30) {
tol = ControlComputer(tol);
if (tol == 30) {
printf("Player lose\n"); }
else { tol = Input(tol); if (tol >= 30)
{ printf("Computer lose\n"); } } }
printf("Game Over");
return 0;}
int Input(int t){
int a;
do { printf("please count\n");
scanf("%d", &a);
if (a > 2 || a < 1) { printf("Error input\n"); }
else { printf("you count is %d\n", t + a); } } while (a > 2 || a < 1);
return t + a;}
int ControlComputer(int s){
int c;
printf("computer count\n");
if (s % 3 == 1) { s++; printf("%d\n", s); }
else if (s % 3 == 2) { s += 2; printf("%d\n", s); }
else { c = Rnd() + 1; s += c; printf("%d\n", s); }
return s;}
int Rnd(){ srand(time(NULL));
return rand() % 2;}</>