SUMMER HEAT(COCONUT) Solution — Codechef JuneLong Challenge
Chefland has 2 different types of coconut, type A and type B. Type A contains only x milliliters of coconut water and type B contains only xb grams of coconut pulp. Chef’s nutritionist has advised him to consume Xa milliliters of coconut water and Xb grams of coconut pulp every week in the summer. Find the total number of coconuts (type A + type B) that Chef should buy each week to keep himself active in the hot weather.
- The first line contains an integer T, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, four integers xa, xb, Xa, Xb.
For each test case, output in a single line the answer to the problem.
- xa divides Xa.
- xb divides Xb.
Subtask #1 (100 points): original constraints
100 400 1000 1200
100 450 1000 1350
150 400 1200 1200
TestCase 1: Number of coconuts of Type A required = 1000/100=10 and number of coconuts of Type B required = 1200/400=3. So the total number of coconuts required is 10+3=13.
TestCase 2: Number of coconuts of Type A required = 1000/100=10 and number of coconuts of Type B required = 1350/450=3. So the total number of coconuts required is 10+3=13.
TestCase 3: Number of coconuts of Type A required = 1200/150=8 and number of coconuts of Type B required = 1200/400=3. So the total number of coconuts required is 8+3=11.
The code has been implemented in Java
import java.io.*;/* Name of the class has to be "Main" only if the class is public. */
public static void main (String args) throws java.lang.Exception
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
System.out.println((c/a) + (d/b));
Hope you would have liked the article. Please give 50 claps to this article and follow me for more future programming related blogs.
(Video Editorial Link For Better Explanation)