|
|
back to boardPlease help me!I have MLE #8 Here is mu code(C++): #include <iostream.h> void sdvig(char a[],int n) { char *y; y=new char [n]; int i,j,total=0; for(i=0,j=1;i<n,j<=n;i++,j++) { if(j==n) { y[0]=a[n-1]; } else { y[j]=a[i]; } } for(i=0;i<n;i++) { a[i]=y[i]; } } bool proverka(char x[],char y[],int n) { int total=0,i; for(i=0;i<n;i++) { if(x[i]==y[i]) { total++; } } if(total==n) return true; return false; } const int N=250000; int main() { char x[N],y[N]; int n,i,total=0; cin>>n; for(i=0;i<n;i++) { cin>>x[i]; } for(i=0;i<n;i++) { cin>>y[i]; } if(proverka(x,y,n)==true) { cout<<"0"<<endl; } else { while(true) { total++; sdvig(x,n); if(proverka(x,y,n)==true) { cout<<total; break; } else { if(total==n) { cout<<"-1"<<endl; break; } } } } return 0; } |
|
|