Problem ID :c031. 6.最後一個是誰

New Thread

User 請問我有甚麼沒考慮到嗎

austins96432 SendIMessage
涼麵趁熱吃

c031. 6.最後一個是誰 | From: 118.166.143.179 | Post Date:2019-07-19 10:49:29.0

#include<stdio.h>
#include<stdlib.h>
int main(void){
int input,number;
scanf("%d %d",&input,&number);
int people[input];
for(int i=0;i<input;i++){
people[i]=i+1;
}
int out=0,count=1,now=0;
while(1){
if(out==input-1){
break;
}
while(count!=number){
while(1){
if(people[now]==0){
now++;
if(now==input){
now=0;
}
}else{
now++;
count++;
if(now==input){
now=0;
}
break;
}
}
}
if(people[now]==0){
people[now+1]=0;
}else{
people[now]=0;
}
out++;
now++;
count=1;
}
for(int i=0;i<input;i++){
if(people[i]!=0){
printf("%d\n",people[i]);
break;
}
}
system("pause");
return 0;
}
 


文章類型: 一般 | Reply | Back

New Thread

ZeroJudge Forum