top of page
Click here to go to the home page of AskTheCode.

Summer Heat Codechef Solution in C++ and Java - AskTheCode

Team ATC

Updated: Jun 14, 2021

June Long Challenge 2021 Solution | Summer Heat (COCONUT) Solution | AskTheCode

 

Problem:

Chefland has 2 different types of coconut, type A and type B. Type A contains only xa 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.

 

Input:

  • 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.

 

Output:

For each test case, output in a single line the answer to the problem.

 

Subtasks:

Subtask #1 (100 points): original constraints

 

Sample Input:

3
100 400 1000 1200
100 450 1000 1350
150 400 1200 1200
 

Sample Output:

13
13
11
 

EXPLANATION:

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.

 

Code:


In C++ :

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,j=0;
    cin>>n;
    int a[n][4];
    for(int i=0;i<n;i++)
    for(int j=0;j<4;j++)
    {
        cin>>a[i][j];
    }
    for(int i=0;i<n;i++)
    {
       cout<<((a[i][j+2]/a[i][j])+(a[i][j+3]/a[i][j+1]))<<endl;       
    }
    return 0;

}
 

In Java :

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
  {
    int a,b,c,d,res,t;
    Scanner sc = new Scanner(System.in);
    t=sc.nextInt();
    for(int i =0;i<t;i++){
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();
        int e = c/a;
        int f= d/b;
        res = e+f;
        System.out.println(res);
    }
  }
}

Recent Posts

See All

Comments


bottom of page