Pr CHEFFAV IS MY PROBLEM IAm NOT ABLE TO PASS THE TEST CASE

#include <stdio.h>
#include<string.h>
int main() {
int t;
scanf("%d",&t);
while(t>0){
int n,flag=1,prevflag=1;
scanf("%d",&n);
char s[n],s1[4]=“code”,s3[4]=“chef”;
scanf("%s",s);
char org[n];
//printf("%d",n);
int i;
for( i=0;i<n;i++){ org[i]=s[i];
}
org[i+1]=’\0’;
i=0;
while (org[i+3]!=’\0’){int k=i;
int h=k+3,j=0;
char s2[4];
while(k<=h){s2[j]=org[k];
k++,j++;}
if(s1[0]==s2[0]&&s1[1]==s2[1]&&s1[2]==s2[2]&&s1[3]==s2[3])
{ prevflag =0;}
//printf("%d",prevflag );
if(s3[0]==s2[0]&&s3[1]==s2[1]&&s3[2]==s2[2]&&s3[3]==s2[3]) {if(prevflag ==0){
flag=0;}
else
break;
}
//printf("%d",flag );
i++;
//printf("\n");
}
if(flag==0){printf(“ac\n”);}
else
printf(“wc\n”);
t–;}
return 0;}

Hi @harsha_1999s

I hope you find this video helpful in explaining the logic.
CHEFFAV | FAVOURITE STRING OF CHEF | December CodeDrive 2021 | Problem Solutions | CodeChef

The simple way to do it in python would be as follows

# cook your dish here
t=int(input())
for i in range(t):
    n=int(input())
    a=input()
    x=a.index("code")
    y=a.index("chef")
    if x<y:
        print("AC")
    else:
        print("WA")

This code basically checks for the index of the first occurrence of “code” & “chef”, and afterwards you compare the index of both and print the result.

If you found this useful, check out our other problems and other upcoming contests!
CodeChef Contests
Solve more problems on CodeChef