0% found this document useful (0 votes)
15 views

Basic Programming Test

Uploaded by

chandran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Basic Programming Test

Uploaded by

chandran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Write a program to solve the following 2 problems using any programming language of your choice.

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

1 ≤ A, B, A1, B1, A2, B2 ≤ 4

A, and B are distinct

A1, B1, A2, B2 are pairwise distinct

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.

Example case 3: Neither language has both features 1 and 2.

Solution
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define forn(i,e) for(ll i = 0; i < e; i++)

void solve()

ll a,b,a1,b1,a2,b2;

cin>>a>>b>>a1>>b1>>a2>>b2;

if(a > b) swap(a,b);

if(a1 > b1) swap(a1,b1);

if(a2 > b2) swap(a2,b2);

if(a == a1 && b == b1)

cout<<1<<endl;

else if(a == a2 && b == b2)

cout<<2<<endl;

else

cout<<0<<endl;

}
}

int main()

ll t=1;

cin >> t;

forn(i,t) {

solve();

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy