Computer Science, asked by 1hk19cs164, 19 days ago

John and Joe are playing a game. Initially, they have a string of length n consisting of zeros and ones only. Both the players are playing game optimally taking alternate turns. In each turn, the player removes only one occurrence of either substring "01" or "10" from anywhere in the given binary string. The player who cannot make a move loses the game. If John makes the first move, he wonders who will win the game. You, being his friend, help him solve his problem.

Answers

Answered by lysandraviegas02
1

Answer:

Ggle

Explanation:

Mark me Brainliest and follow

Answered by sourasghotekar123
1

Input Format

1. The number of test cases is indicated on the first line by the integer t.

2. Each test case starts with an integer n, which represents the string's length.

3. The second line of each test case contains the initial string.

Constraints

1. 1t50

2. 1 ≤ n ≤ 2\times 10^{5}

3. It is certain that the initial string will only include zeros and ones.

Output Format

If John wins the game, display "John" in a new line for each test case; otherwise, print "Joe."

Sample Input

2\\101\\

Sample Output

John

Joe

Program Code

int main()

{

int t;

cin>>t;

while(t!=0)

{

   int n;

   string s;

   cin>>n;

   cin>>s;

   queue<char> q;

   int i=0;

   while(i &lt; n){

      q.push(s[i]);

       i++;

   }

   bool a=true;

   int k = q.size();

  i = 0;

   while(q.size() &gt; =2&&i &lt; k ){

               char x = q.front();

                   q.pop();

                   chary q.front();

                   q.pop();

                   if((x=='0' &&y=='0') || (x=='1'&&y=='1'))

{

                       q.push(x);

                      q.push(y);

                        i++;  

                   } else{

                       i=0;

                      k=q.size();

                       a = !a;

                   }

        }

   if(a == true) cout<<"Joe"<<endl;

   else cout<<"John"<<endl;

   t--;

}

return 0;

}

Hence, the above program code allows you to find out who will win the game.

#SPJ3

Similar questions