Hello coders, today we are going to solve The Block Game Codechef Solution Which is part of Codechef.

Problem
The citizens of Byteland regularly play a game. They have blocks each denoting some integer from 0 to 9. These are arranged together in a random manner without seeing to form different numbers keeping in mind that the first block is never a 0. Once they form a number they read in the reverse order to check if the number and its reverse is the same. If both are same then the player wins. We call such numbers palindrome.
Ash happens to see this game and wants to simulate the same in the computer. As the first step he wants to take an input from the user and check if the number is a palindrome and declare if the user wins or not.
Input
The first line of the input contains T, the number of test cases. This is followed by T lines containing an integer N.
Output
For each input output “wins” if the number is a palindrome and “loses” if not, in a new line.
Constraints
1 <= T <= 20
1 <= N <= 20000
Input:
3 331 666 343
Output:
loses wins wins
The Block Game CodeChef Solution in Python
for i in range(int(input())): n = input() if n == n[::-1]: print("wins") else: print("loses")
The Block Game CodeChef Solution in CPP
#include <iostream> using namespace std; int main() { int t; cin>>t; while(t--){ int n , rem =0, a; cin>>n; a = n; while(a>0){ rem = rem*10 + a%10; a = a/10; } if(rem == n){ cout<<"wins"<<endl; }else{ cout<<"loses"<<endl; } } return 0; }
The Block Game CodeChef Solution in JAVA
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 sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i<t; i++) { int n = sc.nextInt(); int temp = n; int rev = 0; while(temp>0) { int rem = temp%10; rev = rev*10 + rem; temp = temp/10; } if(rev==n) { System.out.println("wins"); } else { System.out.println("loses"); } } sc.close(); } }
Disclaimer: The above Problem (The Block Game) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.