Tongji Online Judge
Problem 1012: 约瑟夫问题
#include<stdio.h>
typedef struct person{
int index;
int key;
} person;
int main()
{
person a[101];
int start,cur=1,i;
while(scanf("%d %d", &a[0].index, &a[0].key)!=EOF) {
for(i=1; i<=a[0].index; i++) {
a[i].index=i;
scanf("%d", &a[i].key);
}
while(a[0].index) {
start=(cur-1)%a[0].index+1;
cur=(start+a[0].key-2)%a[0].index+1;
if(a[0].index!=1) printf("%d ", a[cur].index);
else printf("%d/n", a[cur].index);
a[0].key=a[cur].key;
for(i=cur+1; i<=a[0].index; i++) {
a[i-1].index=a[i].index;
a[i-1].key=a[i].key;
}
a[0].index--;
}
}
return 0;
}