Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
已经WA了不下30次了,望高手不吝赐教,不胜感激!#include<string.h> #include<stdio.h> void sort(char str[],int m,int sn[]) { char temp[300]; for(int i=0;i<m;i++) temp[sn[i]-1]=str[i]; temp[m]='\0'; for(i=0;i<m;i++) str[i]=temp[i]; } int main() { char str[300],s[300],ss[300]; int num[300],m[300],mm[300][300],n,t,j,k; while(scanf("%d",&n)&&n) { for(int i=0;i<n;i++) scanf("%d\n",&num[i]); long sum=1; for(i=1;i<=n;i++) { k=i; m[i-1]=1; j=0; while(num[k-1]!=i) { ss[j++]=k-1; k=num[k-1]; m[i-1]++; } ss[j]=k-1; for(k=1;k<=j;k++) mm[i-1][j-k+1]=ss[k]; mm[i-1][0]=ss[0]; } // for(i=0;i<3;i++) printf("%d\n",mm[0][i]); while(gets(str)&&strcmp(str,"0")!=0) { for(i=0;i<=strlen(str);i++) { if(s[i]==10 || s[i]==0) s[i]=' '; } //scanf("\n"); t=0; j=0; k=0; for(i=0;i<n;i++) s[i]=' '; s[n]='\0';i=0; while(str[i]!=' ') t=t*10+(str[i++]-'0'); while(str[++i]!='\0') s[j++]=str[i];s[j]='\0'; for(i=0;i<n;i++) printf("%c",s[mm[i][t%m[i]]]); printf("\n"); } printf("\n\n"); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator