# Utkarsh and Placement tests UTKPLC Solution Codechef

## Utkarsh and Placement tests UTKPLC Solution

Utkarsh is currently sitting for placements. He has applied to three companies named A,B and C. You know Utkarsh’s order of preference among these 3 companies, given to you as characters `first``second`, and `third` respectively (where `first` is the company he prefers most).

You also know that Utkarsh has received offers from exactly two of these three companies, given you as characters x and y. Utkarsh will always accept the offer from whichever company is highest on his preference list. Which company will he join?

Input Format

• The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains three different space-separated characters: `first``second`, and `third`, denoting Utkarsh’s order of preference among the three companies.
• The second line of each test case contains two space-separated characters x and y, the companies from which Utkarsh has received offers.

Output Format

• For each test case, print one line containing a single character, the company whose offer Utkarsh will accept.
• The output is not case sensitive, so if the answer is A, both aa and A will be accepted.

Constraints

• 1≤T≤36
• `first``second` and `third` are three different characters among {A,B,C}.
• x and y are two different characters among {A,B,C}.

Subtask #1 (100 points): Original constraints

Sample Input 1

``````2
A B C
A B
B C A
A C``````

Sample Output 1

``````A
C``````

Explanation

Test Case 1. Utkarsh has received offers from A and B. Of these two, he prefers company A (first preference) over B (second preference). Therefore Utkarsh will accept the offer of company A.

Test Case 2. Utkarsh has received offers from A and C, where company C is his second preference and company A is his third preference. Utkarsh will accept the offer of company C.

### SOLUTION

Program Python: Utkarsh and Placement tests UTKPLC Solution in Python

``````for _ in range (int(input())):
a,b,c=map(str,input().split())
d,e=map(str,input().split())
if a == d:
print(d)
elif a == e:
print(e)
elif b==d:
print(d)
else:
print(e)``````

Program C++: Utkarsh and Placement tests UTKPLC Solution in C++

Credit: pirate_helper (in comment section)

``````#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
char first , second, third,x,y;
cin >> first >> second >> third;
cin >> x >> y;
if(first == x) {
cout << x << endl;
} else if(first ==y) {
cout << y << endl;
} else if(second ==x){
cout << x <<endl;
}else{
cout << y << endl;
}
}
return 0;
}``````

## December Long Challenge 2021 Solution

### 2 thoughts on “Utkarsh and Placement tests UTKPLC Solution Codechef”

1. #include

using namespace std;

int main() {
int t;
cin >> t;
while(t–) {
char first , second, third,x,y;
cin >> first >> second >> third;
cin >> x >> y;
if(first == x) {
cout << x << endl;
} else if(first ==y) {
cout << y << endl;
} else if(second ==x){
cout << x <<endl;
}else{
cout << y << endl;
}
}
return 0;
}

• 