Help me in solving SMILEY problem

My issue

My code

#include <stdio.h>
#include<stdlib.h>


int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int l;
	    scanf("%d",&l);
	    char s[l];
	    scanf("%s",s); int *n=(int*)calloc(100000,sizeof(int)); int j=0;
	    for(int i=0; i<l; i++)
	    {
	        if(s[i]==':')
	        {
	            n[j]=i; 
	        j++;
	        }
	    }
	    int count=0; int flag=0;
	    
	    for(int i=0; n[i+1]!=0; i++)
	    {
	        if(n[i+1]-n[i]!=0)
	        {
	            for(int k=n[i]+1 ; k<n[i+1]; k++)
	            {
	                if(s[k]==')')
	                flag=1;
	                else
	               { flag=0;
	                break; }
	            }
	            if(flag)
	            count++;
	        }
	    }
	    printf("%d\n",count);
	    
	}
	return 0;
}


Problem Link: SMILEY Problem - CodeChef
What’s wrong in this code?

@sagunsingh
one little mistake
u have to redefine flag=0 in the if condition

1 Like

okay, can you please clarify which if are you actually talking about?

@sagunsingh
if(n[i+1]-n[i]!=0)

1 Like