Wednesday, 20 September 2017

The Block Game Problem

The Block Game


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 are 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 and output "wins" if the number is a palindrome and "losses" if not.

Constraints

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

Examples

Input:
3
331
666
343

Output:
losses
wins
wins


Solution:

#include <stdio.h>
#include <math.h>

int pal(int n){
int T[10], k=0, i, j;
while(n>0){
T[k]=n%10; k++; n/=10;
}
for(i=0,j=k-1;i<j;i++,j--)
if(T[i]!=T[j]) return 0;

return 1;
}

int main(){
int t, n;

scanf("%d",&t);

while(t--){
scanf("%d",&n);
if(pal(n)==1) printf("wins\n");
else printf("losses\n");
}

return 0;

No comments:

Post a Comment