CIELNUM2: Need help, getting tle

Problem:CIELNUM2

not sure why this is timing out

EDIT: Now i increased the size of s and the code gives WA now :expressionless:

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        int t,count=0;
        scanf("%d\n",&t);
        for(int k=0;k<t;k++){
                bool flag=true;
                char s[201];
                char chr,temp1;
                int index=0,l,count3,count5,count8;
                count3=count5=count8=0;
                gets(s);
                l=strlen(s);
                for(int i=l-1;s[i]!=' ';i--){
                        index++;
                }
                for(int i=l-index;i<l;i++){
                        temp1=s[i];
                        if(temp1=='3')
                                count3++;
                        else if(temp1=='5')
                                count5++;
                        else if(temp1=='8')
                                count8++;
                        else{
                                flag=false;
                                goto x;
                        }
                }
                if(!(count8>=count5&&count5>=count3))
                        flag=false;
                x:
                if(flag)
                        count++;
        }
        printf("%d\n",count);
        return 0;
}

You are using gets to take whole line as a input in s(char array). But it is clearly said that the length of si <=100 and there is a number Pi which also has some lenght. So your s[101] does not provide sufficient space to store the whole line and this may result in TLE.

1 Like
//