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 |
怎能求循环阶数啊??我这个总是超时..........高手指点一二#include <stdio.h> #include <string.h> int euclid(int p,int q) { int tmp; while(q!=0) { tmp=p%q; p=q; q=tmp; } return p; } int main() { int n,k,i,j,mi=1,len,t; char *p,*q,*temp; scanf("%d",&n); while(n!=0) { int *N=new int [n]; int *M=new int [n]; char *a=new char [n+1]; char *b=new char [n+1]; for(i=0;i<n;i++) { scanf("%d",&N[i]); M[i]=N[i]; } for(i=0;i<n;i++) { len=0; while(M[i]!=0) { len++; t=M[i]; M[i]=0; i=t-1; } if(len!=0&&len!=1&&mi%len!=0) mi=(mi*len)/euclid(mi,len); } printf("%d\n",mi); scanf("%d",&k); while(k!=0) { getchar(); gets(a); for(i=strlen(a);i<n;i++) a[i]=' '; a[n]='\0'; b[n]='\0'; p=a; q=b; k=k%mi; for(i=0;i<k;i++) { for(j=0;j<n;j++) q[N[j]-1]=p[j]; temp=p; p=q; q=temp; } printf("%s\n",p); scanf("%d",&k); } printf("\n"); scanf("%d",&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