两方分别报数 谁先报到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;}</>
你的程序可以稍微整理下吗,把题目发我,我试试看
根据题目给出的计算机报数规则,我们可以推测出程序中变量s的含义。变量s代表的是剩余的数除以3的余数。在程序中,通过对s的值进行判断,来确定计算机报数的个数。
首先,我们可以观察规律并进行推理:
根据上述规则,s可以取0、1、2三个值,分别表示剩余的数除以3的余数为0、1、2。
当s为0时,意味着剩余的数可以被3整除。因此,根据规则,计算机会随机报一或两个数。
当s为1时,意味着剩余的数除以3的余数为1。因此,根据规则,计算机会报一个数。
当s为2时,意味着剩余的数除以3的余数为2。因此,根据规则,计算机会报两个数。
所以,根据题目给出的计算机报数规则,变量s的值表示剩余的数除以3的余数,不是剩余数的个数。