Basic Programming Test
Basic Programming Test
Problem #1
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.
Constraints
1<=T<=20
1<=N<=20000
Sample 1:
Input
3
331
666
343
Output
loses
wins
wins
Solution
for i in range(int(input())):
n = input()
if n == n[::-1]:
print("wins")
else:
print("loses")
Problem #2
Chef is a software developer, so he has to switch between different languages sometimes. Each
programming language has some features, which are represented by integers here.
Currently, Chef has to use a language with two given features A and B. He has two options ---
switching to a language with two features A1 and B1, or to a language with two features A2 and B2.
All four features of these two languages are pairwise distinct.
Tell Chef whether he can use the first language, the second language or neither of these languages
(if no single language has all the required features).
Input
The first line of the input contains a single integer T denoting the number of test cases. The
description of T test cases follows.
The first and only line of each test case contains six space-separated integers A, B, A1, B1,
A2, B2.
Output
For each test case, print a single line containing the integer 1 if Chef should switch to the first
language, 2 if Chef should switch to the second language, or 0 if Chef cannot switch to either
language.
Constraints
1 ≤ T ≤ 288
Sample 1
Input
3
122134
342143
121324
Output
1
2
Explanation
Example case 1: The first language has the required features --- features 1 and 2.
Example case 2: The second language has the required features --- features 3 and 4.
Solution
#include <bits/stdc++.h>
void solve()
ll a,b,a1,b1,a2,b2;
cin>>a>>b>>a1>>b1>>a2>>b2;
cout<<1<<endl;
cout<<2<<endl;
else
cout<<0<<endl;
}
}
int main()
ll t=1;
cin >> t;
forn(i,t) {
solve();
return 0;