N – TV Discount

Chef is looking to buy a TV and has shortlisted two models. The first one costs π΄A rupees, while the second one costs π΅B rupees.

Since there is a huge sale coming up on Chefzon, Chef can get a flat discount of πΆC rupees on the first TV, and a flat discount of π·D rupees on the second one.

Help Chef determine which of the two TVs would be cheaper to buy during the sale.

Input Format

  • The first line contains a single integer π‘‡T β€” the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains four space-separated integers π΄A, π΅B, πΆC and π·D β€” the marked price (in rupees) of the first TV, the marked price (in rupees) of the second TV, the flat discount (in rupees) of the first TV, and the flat discount (in rupees) of the second TV.

Output Format

For each test case, print a single line containing the string First if the first TV is cheaper to buy with discount, or Second if the second TV is cheaper to buy with discount. If both of them cost the same after discount, print Any.

You may print each character of the string in uppercase or lowercase (for example, the strings firstFirstfIRSt, and FIRST will all be treated as identical).

Constraints

  • 1≀𝑇≀50001≀T≀5000
  • 1≀𝐴,𝐡≀1001≀A,B≀100
  • 0≀𝐢≀𝐴0≀C≀A
  • 0≀𝐷≀𝐡0≀D≀B

Sample 1

InputcopyOutputcopy
3
85 75 35 20
100 99 0 0
30 40 0 10
First
Second
Any

Test case 11: The cost of the first TV after discount is 85βˆ’35=5085βˆ’35=50, while the cost of the second TV after discount is 75βˆ’20=5575βˆ’20=55. Thus the first TV is cheaper to buy than the second.

Test case 22: The cost of the first TV after discount is 100βˆ’0=100100βˆ’0=100, while the cost of the second TV after discount is 99βˆ’0=9999βˆ’0=99. Thus the second TV is cheaper to buy than the first.

Test case 33: The cost of the first TV after discount is 30βˆ’0=3030βˆ’0=30, while the cost of the second TV after discount is 40βˆ’10=3040βˆ’10=30. Since they are equal, Chef can buy any of them.

Solutions:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int i = 0; i < T; i++) {
            int A = scanner.nextInt();
            int B = scanner.nextInt();
            int C = scanner.nextInt();
            int D = scanner.nextInt();
            int costFirstTV = A - C;
            int costSecondTV = B - D;
            if (costFirstTV < costSecondTV) {
                System.out.println("First");
            } else if (costFirstTV > costSecondTV) {
                System.out.println("Second");
            } else {
                System.out.println("Any");
            }
        }
        scanner.close();
    }
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top