记录一下 不知道会不会被同学搜到= =!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXN 1000
int cipher[MAXN],flag[MAXN],start,n;
char ch;
int main()
{
FILE *fp;
fp=fopen("E:\\ex1.txt","r");
int i=0,cnt=0,head,nn;
memset(flag,1,sizeof(flag));
fscanf(fp,"%d",&start);
while(fscanf(fp,"%d%c",&cipher[i++],&ch))
{
if(ch=='\n') break;
n=i;
}
n++;head=start-1;
flag[(head+cipher[head]-1)%n]=0;
printf("%d ",(head+cipher[head])%n);
head=(head+cipher[head])%n;
nn=n;
while(nn>1)
{
i=head;cnt=0;
if(head==0) head=n;
while(cnt<cipher[head-1])
{
if(i>=n) i%=n;
if(flag[i]) ++cnt;
i++;
}
i--;
printf("%d ",i+1);
--nn;
flag[i]=0;
head=(i+1)%n;
}
getchar();
}