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:为什么run time error 啊?求救!!大虾帮忙!!In Reply To:Re:为什么run time error 啊?求救!!大虾帮忙!! Posted by:cpp050300448135 at 2005-05-11 02:30:52 这个是第二此改变后得程序,先寻找循环节time,然后用取模减少类似1995得多次重复循环……但是由于找公倍数这个步骤得繁琐……所以还是失败了……sigh #include<iostream> #include<string> using namespace std; void main() { int * array, * b, * c, num, k, time; string str,result; while(1) { cin>>num; if(num==0) break; array=new int[num]; b=new int[num]; c=new int[num]; for(int i=0; i<num; i++) { cin>>array[i]; b[i]=i+1; } for(int ii=0; ii<num; ii++) { for(time=i=1;;i++) { b[i-1]=array[b[i-1]-1]; if(b[i-1]==i) break; else time++; } c[ii]=time; } for(i=time=0; i<num; i++) if(c[i]>time) time=c[i]; for(;;time++) { for(int aa=i=0; i<num; i++) { if(!(time%c[i])) aa++; else { break; aa++; } } if(aa==num) break; } for(;;) { cin>>k; if(k==0) break; cin.ignore(1,'\n'); getline(cin, str); str.resize(num, ' '); result.resize(num, ' '); for(i=0; i<(k%time); i++) { for(int j=0; j<num; j++) result[array[j]-1]=str[j]; str=result; } cout<<result; } if(k==0) cin>>num; if(num==0) break; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator