H. Good or Bad – Codeforces Problem Solution in C

Disclaimer: Make sure you tried enough before checking the solution

Problem: https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/H

#include<stdio.h>
#include<string.h>
int main(){
     int n,i,j,f=0;
     char a[100000];
     scanf("%d",&n);
     for(i=0;i<n;i++){
          scanf("%s",a);
          for(j=0;j<strlen(a)-2;j++){
               if((a[j]=='0' && a[j+1]=='1' && a[j+2]=='0') || (a[j]=='1' && a[j+1]=='0' && a[j+2]=='1')){
                    f = 1;
                    break;
               }
               else{
                   f= 0;
               }
          }
     if (f==1) printf("Good\n");
     else if(f==0) printf("Bad\n");
     }


}

Assiut University Training – Newcomers Solution String

Leave a Comment