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 |
居然超了Memory !!!我无语了!!哪位大侠指点一下?#include <iostream> #include <string> #include <malloc.h> using namespace std; int *code; int *cc; int m,n,k; int i,j,l,ll; char c[210]; string a,d; int min(int a,int b); void main() { while(1) { loop: cin>>n; if(n==0) return; code=(int *)malloc(n*sizeof(int)); cc=(int *)malloc((n+1)*sizeof(int)); for(i=0;i<n;i++) { cin>>code[i]; cc[i+1]=code[i]; } m=1; for(i=1;cc[i]!=0&&cc[i]<=n;i++) { l=cc[i]; cc[i]=0; for(j=1;l!=i;j++) { ll=l; l=cc[l]; cc[ll]=0; } m=min(m,j); } while(1) { cin>>k; k=k%m; if(k==0) { cout<<endl; goto loop; } // cin.getline(c,210); int b; a.resize(n+1); d.resize(n+1); // a=c; getline(cin,a); for(i=1;i<=n;i++) { b=i; for(j=0;j<k;j++) { b=code[b-1]; } d[b]=a[i]; } for(i=1;i<=n;i++) cout<<d[i]; cout<<endl; } free(code); free(cc); } } int min(int a, int b) { int i; int m; for(i=1;i<=a&&i<=b;i++) { if(a%i==0) { if(b%i==0) m=i; } } return a*b/m; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator