The Block Game(PALL01): Codechef Solution in C++ Language
THE BLOCK GAME
Problem Code: PALL01
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 Format
Output Format
For each input output "wins" if the number is a palindrome and "loses" if not, in a new line.
Constraints
- 1 ≤ T ≤ 20
- 0 ≤ N ≤ 20000
Sample Input 1
3
331
666
343
Sample Output 1
loses
wins
wins
. . .
Solution in C++.
#include <iostream> using namespace std; int main() { int t; cin >> t; while(t--){ int n, x=0; cin >> n; int a = n; while(n>0){ x = x*10 + n%10; n = n/10; } if(a==x){ cout << "wins" << endl; } else{ cout << "loses" << endl; } } return 0; }
Try Solution On The C-Playground : https://bit.ly/45kwElp
Comments
Post a Comment