-
Notifications
You must be signed in to change notification settings - Fork 0
/
The Block Game
44 lines (39 loc) · 1.43 KB
/
The Block Game
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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.
import java.util.*;
public class codechef
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
String str=sc.next();
int n=str.length();
boolean palindrome=true;
for(int j=0j<n/2;j++)
{
if(str.charAt(j)!=str.charAt(n-1-j))
{
palindrome=false;
break;
}
if(palindrome)
{
System.out.println("wins");
}
else
{
System.out.println("losses");
}
}
}
}