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 |
Re:还真是郁闷,把cout改为printf才勉强不TLE了,唉~In Reply To:还真是郁闷,把cout改为printf才勉强不TLE了,唉~ Posted by:winboycool at 2007-04-26 01:36:36 #include <stdio.h> #include <string.h> #define N 300 //Variables Declarations int pos[N],times; char ch[N]; int main() { int n,k; while(true) { int chlen; char ch_temp[N]; scanf("%d",&n); if(!n) break; //如果n=0 退出 for(int i=1;i<=n;++i) {scanf("%d", &pos[i]);} times=-1; for(int i=1;i<=n;++i) { int j,temp; j=pos[i]; temp=1; while(j!=i) { j=pos[j]; ++temp; } if(times < temp) times=temp; } while(true) { scanf("%d",&k); if(!k) break; //如果k=0 block结束 for(int j=0;j<N;++j) {ch_temp[j]='\0';} k=k%times; if(k==0) k=times; getchar(); gets(ch); chlen=strlen(ch); if(chlen<n) //增加' ' { for(int i=chlen;i<n;++i) {ch[i]=' ';} } ch[n]=0; for(int i=1;i<=k;++i) { for(int j=0;j<n;++j) { ch_temp[pos[j+1]-1]=ch[j]; } strcpy(ch,ch_temp); } printf("%s\n\n",ch); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator