The Cheaper Cab: CABS
The Cheaper Cab CodeChef Solution in C, C++, Java, and Python 3
Public Submission link: Click here (anyone can submit here )
CU Submission link: Click here (need login by CU account)
Chef has to travel to another place. For this, he can avail any one of two cab services.
- The first cab service charges XX rupees.
- The second cab service charges YY rupees.
Chef wants to spend the minimum amount of money. Which cab service should Chef take?
Input Format
- The first line will contain TT – the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two integers XX and YY – the prices of first and second cab services respectively.
Output Format
For each test case, output FIRST if the first cab service is cheaper, output SECOND if the second cab service is cheaper, output ANY if both cab services have the same price.
You may print each character of FIRST, SECOND and ANY in uppercase or lowercase (for example, any, aNy, Any will be considered identical).
Constraints
- 1≤T≤100
- 1≤X,Y≤100
Sample Input 1
3
30 65
42 42
90 50
Sample Output 1
FIRST
ANY
SECOND
The Cheaper Cab CodeChef Solution in C
// your code goes here
int t,x,y;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&x,&y);
if(x< y)
printf("FIRST\n");
else if(x>y)
printf("SECOND\n");
else
printf("ANY\n");
}
return 0;
}
The Cheaper Cab CodeChef Solution in C++ 17
// your code goes here
int t;
cin>>t;
for(int i=0; i < t; i++){
int x , y;
cin>>x>>y;
if(y>x){
cout << "FIRST" << endl;
}
else if(y==x){
cout <<"ANY" << endl;
}
else{
cout <<"SECOND" << endl;
}
}
return 0;
}
The Cheaper Cab CodeChef Solution in Python 3
t = int(input())
for i in range(t):
x,y=map(int,input().split())
tx = 1*x
ty = 1*y
if tx == ty:
print('ANY')
if tx > ty:
print('SECOND')
if tx < ty:
print('FIRST')
The Cheaper Cab CodeChef Solution in Java
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int a = sc.nextInt();
int b = sc.nextInt();
if (a < b){
System.out.println("FIRST");
}else if(a>b){
System.out.println("SECONd");
}
else{
System.out.println("ANY");
}
}
}
}
More Codechef Solution: Click Here
The Cheaper Cab CodeChef Solution from