In this Codechef Chef and Chocolates, problem-solution Chef has X 5 rupee coins and Y 10 rupee coins. The chef goes to a shop to buy chocolates for Chefina where each chocolate costs Z rupees. Find the maximum number of chocolates that the Chef can buy for Chefina.
Problem solution in Python.
t=int(input())
for _ in range(t):
a,b,c=map(int,input().split())
t=a*5+b*10
print(t//c)
Problem solution in Java.
import java.util.Scanner;
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
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
int store;
while(t!=0) {
int x = in.nextInt();
int y=in.nextInt();
int cost =in.nextInt();
x =x*5;
y=y*10;
store = y+x;
store = store/cost;
System.out.println(store);
t--;
}
}
}
Problem solution in C++.
#include <iostream>
using namespace std;
int main()
{ int test_cases,x,y,z;
cin>>test_cases;
while(test_cases--)
{
cin >> x >> y>>z;
int total = 5*x + 10*y;
int max_chocolates = total/z;
cout<< max_chocolates << endl;
}
return 0;
}
Problem solution in C.
#include <stdio.h>
int main(void) {
int t;
scanf("%d",&t);
while(t--){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int d=(a*5)+(b*10);
int e=d/c;
printf("%d\n",e);
}
return 0;
}

0 Comments