ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1423. String Tale

Can somebody help me ?
Posted by RoskaTa [C++ rLz] 29 Dec 2008 14:47
#include<iostream>
#include<string>
using namespace std;

string s1,s2,t;

int main()
{
    int n,i=0,j,sz;
    cin>>n;
    cin>>s1>>t;
    while(1)
    {
        if(s1==t)
        {
            cout<<i<<endl;
            break;
        }
        if(i>=n)
        {
            cout<<"-1"<<endl;
            break;
        }
        s2=s1.at(n-1);
        s1.erase(n-1);
        s2+=s1;
        s1=s2;
        i++;
    }
    return 0;
}


I get time limit -- > Time limit exceeded 8 1.015
Can somebody help me with an idea how to make it run faster ?
Thanks in advance :)

Edited by author 29.12.2008 14:48