耶稣有13个门徒,其中有一个就是出卖耶稣的人,报数,1,2,3,1,2,3,1,2,3…凡是报到3的就退出圈子,最后留在圈中的就是出卖耶稣的叛徒,请找出它原来的序号.
解决方案:20分
仅供参考
#include <stdio.h> int main() { int a[13]; for (int i = 0; i < 13; i++) a[i] = 1; void fun(int *, int); fun(a, 13); return 0; } void fun(int *a, int size) { int flag = 0,mun = size,*yuan=a; while (mun > 1) { for (flag = 1; flag < 4; flag++) { if (a == yuan + size) a = yuan; while (*a == 0) { a++; if (a == yuan + size) a = yuan; } if (flag == 3) { *a = 0; mun--; } a++; } } a = yuan; for (; a < yuan + size;a++) if (*a != 0) { printf("是原来第%d号!\n", a - yuan + 1); break; } }