The Block Game (CodeChef Problem code: PALL01 )

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 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 "losses" if not.

Constraints

1<=T<=20
1<=N<=10000

Input:
3
331
666
343

Output:
losses
wins
wins
     
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std ;
int reverseNo(int ) ;
int main()
{
int t,no,org,rev ;
cin>>t ;
while(t--)
{
cin>>no ;
org=no ;
rev=reverseNo(no) ;

if(rev==org)
cout<<"wins" ;
else
cout<<"losses" ;

cout<<endl ;
}
return 0 ;
}

int reverseNo(int no)
{
int rem,s ;
s=0 ;
while(no!=0)
{
rem=no%10 ;
s=s*10+rem ;
no=no/10 ;
}
return s ;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )