attic problem cook off june .

can someone please tell me why my code was giving WA ?

#include<stdio.h>
#include<string.h>
 
 
 
int main()
{
	int times,i,k,sum=0;   
	scanf("%d",&times);
	for( i=0;i<times;i++)
	{ 
	     char p[1000000];   
		int j=0,longest=0,result=0;
 
		scanf("%s",p);
	//	printf("%s\n",p);
	//	printf("strlen%d\n",strlen(p));
	//	while(p[j]!='\0')  
 
	
	
	   for(j=0;j<strlen(p);j++)
	    {
     
        	if(p[j]=='.')
        	{sum=0;
        		for( k=j;p[k]!='#';k++)
                {
                	sum++;                
                }			
				if(sum>longest)        		
				{
				longest=sum;        		
        		result++;
        	    }
        
        	}
        	
          	
        }		
		
		
		
		
	printf("%d\n",result);	
     
	}
	
	
	return 0;
}

try .#. it gives 2 while right ans is 1 hope this helps :slight_smile:
because in the second loop u didn’t check the strlen’s condition

1 Like

but .#. shouldn’t be a test case right ? since there was a constraint " The first and the last characters of P will be #" ???

here the code which got accepted first increase the char size because ‘\0’ is also to be store so make for caution i made it 10^7 and it is global then after this it will give tle to reduce tle make j=k-1 since #…# u don’t want the last dot been processed for 4 times :slight_smile:

#include<stdio.h>
#include<string.h>
char p[10000000];
int main()
{
int times,i,k,sum=0;
scanf("%d",&times);
for( i=0;i<times;i++)
{
int j=0,longest=0,result=0;

	scanf("%s",p);
	//  printf("%s\n",p);
	//  printf("strlen%d\n",strlen(p));
	//  while(p[j]!='\0')
	for(j=0;j<strlen(p);j++)
	{

		if(p[j]=='.')
		{
			sum=0;
			for( k=j;p[k]!='#';k++)
			{
				sum++;                
			} 
	      		j=k-1;	
			if(sum>longest)             
			{
				longest=sum;                
                                result++;
			}
		}
	}
	printf("%d\n",result);
}
return 0;

}

1 Like

ohhh…silly me … thanks a lot :slight_smile: @aabhas08

//