Speed Limit Test Solution Codechef
Alice is driving from her home to her office which is A kilometers away and will take her X hours to reach.
Bob is driving from his home to his office which is B kilometers away and will take him Y hours to reach.
Determine who is driving faster, else, if they are both driving at the same speed print EQUAL.
Input Format
- The first line will contain T, the number of test cases. Then the test cases follow.
- Each test case consists of a single line of input, containing four integers A,X,B, and Y, the distances and and the times taken by Alice and Bob respectively.
Output Format
- For each test case, if Alice is faster, print ALICE. Else if Bob is faster, print BOB. If both are equal, print EQUAL.
- You may print each character of the string in uppercase or lowercase (for example, the strings equal, equAL, EquAl, and EQUAL will all be treated as identical).
Constraints
- 1≤T≤1000
- 1≤A,X,B,Y≤1000
Sample Input 1
3
20 6 20 5
10 3 20 6
9 1 1 1
Sample Output 1
Bob
Equal
Alice
Explanation
- Test case 1: Since Bob travels the distance between his office and house in 5 hours, whereas Alice travels the same distance of 20 kms in 6 hours, BOB is faster.
- Test case 2: Since Alice travels the distance of 10 km between her office and house in 3 hours and Bob travels a distance of 20 km in 6 hours, they have equal speeds.
- Test case 3: Since Alice travels the distance of 9 km between her office and house in 1 hour and Bob travels only a distance of 1 km in the same time, ALICE is faster.
SOLUTION
Program: Speed Limit Test Solution in Python
for _ in range(int(input())):
a,x,b,y = map(int, input().split())
if a/x > b/y :
print('Alice')
elif a/x == b/y :
print('Equal')
else :
print('Bob')
Program: Speed Limit Test Solution in C++
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
while(n--)
{
float a,b,x,y;
cin>>a>>b>>x>>y;
if(a/x > b/y)
{
cout<<"Alice"<<endl;
}
else if(a/x < b/y)
{
cout<<"Bob"<<endl;
}
else
cout<<"Equal"<<endl;
}
return 0;
}
Program: Speed Limit Test Solution in Java
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int tt=0; tt<t;tt++){
int a = in.nextInt();
int x = in.nextInt();
int b = in.nextInt();
int y = in.nextInt();
if((1.0*a)/x >(1.0*b)/y){
System.out.println("Alice");
}
else if((1.0*a)/x ==(1.0*b)/y){
System.out.println("Equal");
}
else{
System.out.println("Bob");
}
}
}
}