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 1102. Strange Dialog

Mihran Hovsepyan Why TLE 1? [2] // Problem 1102. Strange Dialog 9 Feb 2009 23:14
Please help me I can't find my mistake

# include <iostream>
# include <string>
using namespace std;

int main()
{
    int i,j,n,k,m;
    char a[6],temp[6],c;
    bool b[6],t,f=false;
    for(i=1;i<6;i++)
        b[i]=false;
    b[0]=true;
    t=true;
    cin>>n;
    cin.get(c);
    i=0;
    while(cin.get(c))
    {
        if(c==EOF)
            break;
        if(c=='\n')
        {
            t=true;
            n--;
            if(n==0)
                break;
            if(b[i])
                printf("YES\n");
            else
                printf("NO\n");
            for(i=1;i<6;i++)
                b[i]=false;
            b[0]=true;
            i=0;
            continue;
        }
        i=(i+1)%6;
        if(t)
        {
            a[i]=c;
            t=false;
            for(j=i-1;j>=i-6;j--)
            {
                if(b[(j+6)%6])
                {
                    k=j+1;
                    m=0;
                    t=true;
                    for(;k<=i;k++)
                        temp[m++]=a[(k+6)%6];
                    temp[m]='\0';
                    if( strcmp(temp,"in")==0 ||
                        strcmp(temp,"out")==0 ||
                        strcmp(temp,"one")==0 ||
                        strcmp(temp,"input")==0 ||
                        strcmp(temp,"puton")==0 ||
                        strcmp(temp,"output")==0)
                    {
                        b[i]=f=true;
                        break;
                    }
                }
            }
            if(!f)
                b[i]=false;
            f=false;
        }
    }
    if(b[i])
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

Edited by author 09.02.2009 23:58
Grigor Gevorgian Re: Why TLE 1? [1] // Problem 1102. Strange Dialog 11 Feb 2009 21:18
Just read the whole input and reverse it. this string is decoded very easy if it's read backward :)
Vedernikoff 'Goryinyich' Sergey (HSE: АОП) Re: Why TLE 1? // Problem 1102. Strange Dialog 12 Feb 2009 01:18
Input from cin is VERY slow. Use faster reading functions (scanf(), gets(), ...)