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
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 | import java.util.*; import java.lang.*; import java.math.*; public class Mock4{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); String line =System.getProperty("line.separator"); scan.useDelimiter(line); int cases = scan.nextInt(); for(int x=0;x<cases;x++){ String get = scan.next(); StringBuilder str = new StringBuilder(get); if(get.equals(str.reverse().toString())) System.out.println("wins"); else System.out.println("loses"); } } } |
No comments:
Post a Comment