Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Chef and Gym CodeChef Solution

Problem – Chef and Gym CodeChef Solution

Chef has decided to join a Gym in ChefLand and if possible, also hire a personal trainer at the gym. The monthly cost of the gym is X and personal training will cost him an additional Y per month. Chef’s total budget per month is only Z. Print 1 if Chef can only join the gym, 2 if he can also have a personal trainer, and 0 if he can’t even join the gym.

Note that if Chef wants to hire a personal trainer, he must join the gym — he cannot hire the trainer without joining the gym.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases. Then the test cases follow.
  • Each test case consists of a single line of input containing three space-separated integers X,Y,Z.

Output Format

For each test case, output in a single line 2 if Chef can go to the gym and have a trainer, 1 if Chef can only go to the gym, 0 if he can’t even go to the gym.

Constraints

  • 1≤T≤100
  • 1≤X,Y,Z≤100

Sample 1:

Input: 4
1 2 3
10 12 13
23 1 22
23 1 63
Output: 2
1
0
2

Explanation:

Test case 1: Since the total cost of Chef getting a gym membership and a trainer is 1+2=3 which is equal to his budget of 3, Chef can get both a gym membership and a trainer.

Test case 2: Since the total cost of Chef getting a gym membership and a trainer is 10+12=22 which is greater than his budget of 13, he can’t get both a gym membership and a trainer. However, the cost of the gym membership is 10 which is less than his budget of 13, so Chef can get only a gym membership.

Test case 3: Since the cost of Chef getting a gym membership is 23 which is greater than his budget of 22, Chef can’t even get the gym membership.

Test case 4: The same costs as the previous test, but this time Chef has enough money to afford both the membership and a personal trainer.

Chef and Gym CodeChef 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 scn= new Scanner(System.in);    //System.in is a standard input stream  
        int T= scn.nextInt();
        
       for(int i=0; i<T; i++){
        int X= scn.nextInt();
        int Y= scn.nextInt();
        int Z= scn.nextInt();
       
        if(Z>=X){
            if(Z==X){
                System.out.println(1);
        }   else if(X+Y<=Z){
                System.out.println(2);
        }
             else{
                System.out.println(1);
        }
        }
        else{
            System.out.println(0);
        }
       }
	}
}

Chef and Gym CodeChef Solution in Pyth 3

T = int(input())
for i in range(T):
    X,Y,Z=map(int,input().split())
    if (X+Y)<=Z:
        print("2")
    elif (X+Y)>=Z and X>Z :
        print("0")
    else:
        print("1")

Chef and Gym CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
    int t; cin>>t; while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        cout<<(c>=a+b ? 2 : (c>=a ? 1 : 0))<<endl;
    }
	// your code goes here
	return 0;
}
Chef and Gym CodeChef Solution Review:

In our experience, we suggest you solve this Chef and Gym CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Chef and Gym CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Chef and Gym CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

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