# Chef and Feedback | CodeChef Solution

Hello coders, today we are going to solve Chef and Feedback CodeChef Solution whose Problem Code is ERROR.

Contents

Lots of geeky customers visit our chef’s restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters ‘0’ and ‘1’.Now since chef is not that great in deciphering binary strings, he has decided the following criteria to classify the feedback as Good or Bad :

If the string contains the substring “010” or “101”, then the feedback is Good, else it is Bad. Note that, to be Good it is not necessary to have both of them as substring.

So given some binary strings, you need to output whether according to the chef, the strings are Good or Bad.

## Input Format

The first line contains an integer T denoting the number of feedbacks. Each of the next T lines contains a string composed of only ‘0’ and ‘1’.

## Output Format

For every test case, print in a single line Good or Bad as per the Chef’s method of classification.

## Constraints

• ≤ T ≤ 100
• ≤ |S| ≤ 105

Sum of length of all strings in one test file will not exceed 6*106.

Example

Sample Input

``````2
11111110
10101010101010``````

Sample Output

``````Bad
Good``````

Explanation

Example case 1.
The string doesn’t contain 010 or 101 as substrings.

Example case 2.
The string contains both 010 and 101 as substrings.

## Solution – Chef and Feedback

### C++

```#include <bits/stdc++.h>
using namespace std;
bool isSubstring(string s1, string s2)
{
int n = s1.size();
int m = s2.size();
for (int i = 0; i < n - m + 1; i++)
{
int j;
for (j = 0; j < m; j++)
{
if (s1[i + j] != s2[j])
break;
}
if (j == m)
return true;
}
return false;
}

int main()
{
int t;
cin >> t;
while (t--)
{
string s;
cin >> s;
if (isSubstring(s, "101") || isSubstring(s, "010"))
{
cout << "Good" << endl;
}
else
}
return 0;
}

```

### Python

```for i in range(int(input())):
s = input()
if "101" in s or "010" in s:
print("Good")
else:

### Java

```/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-->0){
String s = scan.next();
String a = "101", b = "010";
if(s.contains(a) || s.contains(b)){
System.out.println("Good");
}
else{
}
}
}
}
```

Disclaimer: The above Problem (Chef and Feedback) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

### 1 thought on “Chef and Feedback | CodeChef Solution”

1. Hello bro,
I have a easiest way to solve this problem in C++
Below i shared you code please update this blog because it will help all the students.

C++ code
#include
using namespace std;

int main() {
int n;
cin >> n;
while(n–){
string a;
cin >> a;
string b = “101”;
string c = “010”;

if(a.find(b) != string::npos || a.find(c) != string::npos){
cout << "Good" << endl;
}else{