int length = 13;
int j = 0;
int data[13] = {0};
int traitor = 0;
while ((isFinished(data,length)) == 0) {
for (int i = 0; i < length; i ++) {
if (data == 100) {
continue;
}
data = (j % 3) + 1;
if (data == 3) {
data = 100;
traitor = i;
}
j ++;
}
}
printf("叛徒是: %d\n",traitor + 1);
}
int isFinished(int *data,int length)
{
int flag = 1;
for (int i = 0; i < length; i++) {
if (data != 100) {
flag = 0;
}
}
return flag;
}
作者: FlyTrem 时间: 2014-3-28 20:48
#include<stdio.h>
int main()
{
int length = 13; //定义整形变量length,赋值为13
int j = 0; //定义整形变量j赋值为0
int data[13] = {0}; //定义有数组data,且对第一个字符初始化为0
int traitor = 0; //定义整形变量traitor赋值为0
while ((isFinished(data,length)) == 0) { //首先调用isFinished时将data,length传递进去,判断是不是等于0
for (int i = 0; i < length; i ++) { //遍历下角标小于13的数组成员
if (data == 100) { // 如果data等于100
continue; //结束循环
}
data = (j % 3) + 1; //对J和3进行求余且加一赋值给data
if (data == 3) { //如果data等于3
data = 100; //则将100赋值给data
traitor = i; //将i值赋给traitor
int isFinished(int *data,int length) //定义函数传递指针类型和整形变量
{
int flag = 1; //定义局部变量flag赋值为1
for (int i = 0; i < length; i++) { //遍历下角标小于length是所有data的值
if (data != 100) { //如果data等于100
flag = 0; //将0赋值给flag
}
}