https://www.codechef.com/TNP62121/problems/TNP605

#PROBLEM LINK: CodeChef: Practical coding for everyone

Author: Setter’s name

Tester:Tester’s name

Editorialist:Editorialist’s name

DIFFICULTY : EASY

#PREREQUISITES : NIL

#PROBLEM :
The people of Vestland 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 are the same. If both are the same then the player wins. We call such numbers palindrome. Ash happens to see this game and wants to simulate the same on the computer. As the first step, he wants to take input from the user and check if the number is a palindrome and declare if the user wins or not.

(A palindromic number is a number that remains the same when written forward or backward. eg:11,121,262,9449,17371…….)

#SOLUTION:
#include<stdio.h>
#include<math.h>
int main(){
int n ;
scanf(“%d”,&n);
int j;
for(j=0;j<n;j++){
int a=0,b=0,temp=0;
scanf(“%d”,&a);
temp = a ;
while(temp != 0){
b = b*10;
b = b + temp% 10 ;
temp = temp/10 ;
}
if(a== b)
printf(“wins\n”);
else
printf(“loses\n”);
}
return 0 ;
}

#EXPLANATION:

Here, the user is asked to enter an integer. The number is stored in variable ‘a’. We then assigned this number to another variable temp. Then, the reverse of ‘a’ is found and stored in ‘b’.If ‘a’ is equal to ‘b’, the number entered by the user is a palindrome. Hence it will be printed wins otherwise loses.
Sample case: Here the number of test cases is 3 and the numbers are 331,666,343. Each number will be validated whether it is palindrome or not. If the number is palindrome it will be printed wins otherwise loses. Here the result is:
loses
wins
wins