# Dilemma Codechef Solution

#### ByBrokenprogrammers

Dec 17, 2022

Hello Programmers In this post, you will know how to solve the Dilemma Codechef Solution.

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

### Problem

Chef has no work to do in the kitchen, so he decided to play a card game with the following rules:

• Initially, NN cards are placed in a row on a table. Each card is placed either face up or face down.
• The goal of the game is to remove all cards from the table, one by one.
• A card may be removed only if it is currently facing up.
• When a card is removed, its adjacent cards (the cards directly to its left and right, if they exist) are flipped, i.e. a card that was facing up will be facing down and vice versa.
• There is an empty space left behind each removed card, i.e. the remaining cards are not moved to create a contiguous row of cards again. Therefore, if the game starts with three cards and the middle card is removed, then the cards on the sides are flipped, but removing one of these cards afterwards does not cause the other card to be flipped, since it is only adjacent to the empty space created by removing the middle card.

Determine whether Chef is able to win this game.

### Input

• The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
• The first line of each test case contains a single string SS describing the row of cards initially placed on the table. Each character of this string is either ‘1’, denoting a face up card, or ‘0’, denoting a face down card.

### Output

For each test case, print a single line containing the string "WIN" if Chef can win the game or "LOSE" if he cannot win (without quotes).

### Constraints

• 1≤T≤1021≤T≤102
• 1≤|S|≤1051≤|S|≤105

1
10

WIN

### Explanation

Example case 1: First, Chef should remove the first card, which makes the second card face up. Then, he should remove the second card. This way, all cards are removed and Chef wins

### Dilemma CodeChef Solution in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
sc.nextLine();
while(t-->0){
int flag=0;
String str=sc.nextLine();
for(int i=0;i<str.length();i++){
if(str.charAt(i)=='1'){
flag++;
}
}
if(flag%2==0){
System.out.println("LOSE");
}else{
System.out.println("WIN");
}
}
}catch(Exception e){
return;
}
}
}

### Dilemma CodeChef Solution in CPP

#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int count=0;
for(int  i=0; i<s.size();i++){
if(s[i]=='1'){
count++;
}
}
if(count%2==0){
cout<<"LOSE"<<endl;
}
else{
cout<<"WIN"<<endl;
}
}
}

### Dilemma CodeChef Solution in Python

def main():
t=int(input())
c=0;
for j in range(0,t):
a=input();
c=0;
for i in a:
if(i=="1"):
c+=1;
if(c%2==0):
print("LOSE")
else:
print("WIN")
return 0;
if(__name__=="__main__"):
main();

Disclaimer: The above Problem (Dilemma) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.