Utkarsh and Placement tests

 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 firstsecond, 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: firstsecond, 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 a and A will be accepted.

Constraints

  • 1T36
  • firstsecond and third are three different characters among {A,B,C}.
  • x and y are two different characters among {A,B,C}.

Subtasks

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.

Code:

#include <iostream>

using namespace std;


int main() {

int t;

cin>>t;

while(t--)

{

    char a,b,c,e,f;

    cin>>a>>b>>c>>e>>f;

    int lp1 = 0;

    int lp2 = 0;

   

   if(e==a){

       lp1=3;

   }

   else if(e==b){

       lp1 =2;

   }else{

       lp1=1;

   }

   if(f==a){

       lp2=3;

   }else if(f==b){

       lp2=2;

   }else{

       lp2=1;

   }

   

   if(lp1>lp2)

   {

       cout<<e<<endl;

   }

   else{

       cout<<f<<endl;

   }

}

return 0;

}

More Codechef Solution: Click here

Comments

Post a Comment

Popular posts from this blog

Flipkart Runway: Season 3 | 2025 | Internship

Walmart Sparkplug 2022 | 150 students will be selected for summer internship | ₹1-1.1 lakh monthly

Top-order failure leaves India in the doldrums

Software Testing Week 5 : Assignment 5 | 2022