codechef program #10: The Block Game.





PROBLEM STATEMENT:
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 numberspalindrome
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


My Solution:


import java.util.*;


class POP
{


public static boolean isPalindrome(int number) {
        int palindrome = number; 
        int reverse = 0;

        while (palindrome != 0) {
            int remainder = palindrome % 10;
            reverse = reverse * 10 + remainder;
            palindrome = palindrome / 10;
        }

        
        if (number == reverse) {
            return true;
        }
        return false;
    }





public static void main(String args[]){

Scanner in =new Scanner(System.in);
int a=in.nextInt();



for(int i=0;i<a;i++)
{
int c=in.nextInt();
if(isPalindrome(c))
{
System.out.println("wins");
}
else
{
System.out.println("losses");
}


}
}


}



Posted by lol ik

Comments

Popular Posts