数据结构,C语言版的编程问题

2024年11月28日 11:40
有1个网友回答
网友(1):

#include
#include

#define LENGTH 10
#define ANNOUNCER 4

int main(int argc, char **argv){
int array[LENGTH];
int len = LENGTH;
int i, j, left;
for(i = 0; i< LENGTH; i++){//marks the position that is available
array[i] = 1;
}

j = 0;

for(i = 0; i< LENGTH; i = (i+1)%10){//loop until len == 1

if(array[i] != 0){
j++;//counter
}
if(j==ANNOUNCER){//reached 4, out
array[i] = 0;//unmark
len--;
j = 0;
}
if(len == 1){
break;
}
}

for(i = 0;i<10; i++){
if(array[i] != 0){
printf("left: %d\n",i);
}
}

}