Problem
Chef wants to appear in a competitive exam. To take the exam, there are following requirements:
- Minimum age limit is X (i.e. Age should be greater than or equal to X).
- Age should be strictly less than Y.
Chef's current Age is AA. Find whether he is currently eligible to take the exam or not.
Input Format
- First line will contain TT, number of test cases. Then the test cases follow.
- Each test case consists of a single line of input, containing three integers X, Y and A as mentioned in the statement.
Output Format
- For each test case, output YES if Chef is eligible to give the exam, NO otherwise.
- You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical).
Constraints
- 1 ≤ T ≤ 1000
- 20 ≤ X <Y ≤ 40
- 10 ≤ A ≤50
Sample 1:
Input | Output |
---|---|
5 | |
21 34 30 | YES |
25 31 31 | NO |
22 29 25 | YES |
20 40 15 | NO |
28 29 28 | YES |
Explanation:
Test case 11: The age of Chef is 30. His age satisfies the minimum age limit as 30 ≥ 21. Also, it is less than the upper limit as 30 < 34. Thus, Chef is eligible to take the exam.
Test case 22: The age of Chef is 31. His age satisfies the minimum age limit as 31 ≥ 25. But, it is not less than the upper limit as 31 < 31. Thus, Chef is not eligible to take the exam.
Test case 33: The age of Chef is 25. His age satisfies the minimum age limit as 25 ≥ 22. Also, it is less than the upper limit as 25 < 29. Thus, Chef is eligible to take the exam.
Test case 44: The age of Chef is 15. His age does not satisfy the minimum age limit as 15 < 20. Thus, Chef is not eligible to take the exam.
Solution
import java.util.Scanner;
class Codechef
{
public static void main (String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int noOfTc = in.nextInt();
for(int index = 0; index < noOfTc; index++) {
String input = in.nextLine();
while("".equals(input)) {
input = in.nextLine();
}
String[] inputs = input.split(" ");
int x = Integer.parseInt(inputs[0].trim());
int y = Integer.parseInt(inputs[1].trim());
int age = Integer.parseInt(inputs[2].trim());
if (age >= x && age < y) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
The above solution is for the "AGELIMIT" problem on CodeChef. The problem involves determining whether a person is eligible to take an exam based on their age. Here's how the code works:
- The
main
method reads the number of test cases (noOfTc
) from input. - For each test case, it reads a line of input containing three integers
X
,Y
, andA
. - The
while
loop is used to handle any empty lines in the input. - The input line is split using space as the delimiter, resulting in an array
inputs
containing the three values. - The integer values
x
,y
, andage
are parsed from theinputs
array. - The code then checks if the age is greater than or equal to
x
and strictly less thany
. If this condition is satisfied, it prints "YES". Otherwise, it prints "NO".
The solution effectively processes the input test cases and determines whether the person is eligible to take the exam based on the given age limits.
Please note that this code assumes the input follows the provided format and does not include extensive error handling. It's also worth noting that the problem description specifies that 1 ≤ T ≤ 1000, 20 ≤ X < Y ≤ 40, and 10 ≤ A ≤ 50.
Related Articles
- LeetCode 01 : Two Sum
- LeetCode 02 : Add Two Numbers
- LeetCode 03 : Longest Substring Without Repeating Characters
- LeetCode 04 : Container With Most Water
- LeetCode 05 : Remove Duplicates from Sorted Array
- LeetCode 06 : Maximum Subarray
- LeetCode 07 : Contains Duplicate
- Codechef 01 : Problem Code: AGELIMIT
- Codechef 02 : Problem Code: BURGERS