ATTIC problem

Can u tell me whats wrong with the code below , the code is accepted but giving an execution time of 2.53 sec ! How can i optimize it ? Provide some tips !

int main(){

 int t ;
 
 cin>>t;
getchar();
 while(t--){ int days=0,max=0,len=0; char ch; 
            while((ch = getchar()) != '\n') { 
                      
           
                              
            if(ch=='.' ) 
            { 
                       len++;   }
                  
            else 
                { if(len>max){days++; max=len;}  len=0;} 
               
                   
                 
                 
                 }
                 
            cout<<days<<endl; 
            
            }    //system("PAUSE"); 

}

Hello,

That doesn’t mean the code is incorrect… You should read the FAQ to understand what that means.

Best regards,

Bruno

HI Bruno,

I Know my code is correct but still it is giving an execution time of 2.53 sec . I want it to be optimised!

Thanx

One way is using scanf and printf instead of cin and cout. cin/cout are slower.

I think there is only one logic for this question loops might be different or differently implemented
So the only optimisation u should think is input output :slight_smile: hope this code helps u :smiley:

 int main()
    {
         int t ;
    
     scanf("%d",&t);
    getchar_unlocked();
     while(t--){ int days=0,max=0,len=0; char ch; 
                while((ch = getchar_unlocked()) != '\n') {
                if(ch=='.' ) 
                { 
                           len++;   }
    
                else 
                    { 
                      if(len>max){days++; max=len;}  len=0;}
    
                     }
    
                printf("%d\n",days);
    
                }    //system("PAUSE");
    
    }

getchar unlocked instead of printf/scanf

//