Header Ad

Codechef Tasty Decisions problem solution

In this Codechef Tasty Decisions problem solution Chef is buying sweet things to prepare for Halloween!

The shop sells both chocolate and candy.

Each bar of chocolate has a tastiness of XX.

Each piece of candy has a tastiness of YY.

One packet of chocolate contains 22 bars, while one packet of candy contains 55 pieces.

Chef can only buy one packet of something sweet, and so has to make a decision: which one should he buy in order to maximize the total tastiness of his purchase?

Print Chocolate if the packet of chocolate is tastier, Candy if the packet of candy is tastier, and Either if they have the same tastiness.

Codechef Tasty Decisions problem solution


Problem solution in Python programming.

# cook your dish here
n=int(input())
for i in range(n):
    x,y=map(int,input().split())
    a=2*x 
    b=5*y
    if(a>b):
        print("Chocolate")
    elif(a==b):
        print("Either")
    else:
        print("Candy")

Problem solution in Java programming.

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
	{
		Scanner sc=new Scanner(System.in);
		int T=sc.nextInt();
		for(int i=0;i<T;i++){
		    int X=sc.nextInt();
		    int Y=sc.nextInt();
		    int z=X*2;
		    int k=Y*5;
		    if(z>k){
		        System.out.println("chocolate");
		    }
		    else if(z==k){
		        System.out.println("either");
		    }
		    else{
                System.out.println("candy");
		}
		}	
	}
}

Problem solution in C++ programming.

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t=1;
	cin>>t;
	while(t--){
	    int x,y;
	    cin>>x>>y;
	    int tx=2*x,ty=5*y;
	    if(tx>ty)
	    cout<<"Chocolate\n";
	    else if(ty>tx)
	    cout<<"Candy\n";
	    else cout<<"Either\n";
	}
	return 0;
}

Problem solution in C programming.

#include <stdio.h>

int main(void) {
	// your code goes here
	int t,n,m;
	int x,y;
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
	    scanf("%d %d",&x,&y);
	    n= 2*x;
	    m=5*y;
	    if(n>m){
	      printf("Chocolate");
	    }
	    else if(n<m){
	      printf("Candy");
	    }
	    else if(n==m){
	      printf("Either");
	    }
	   printf("\n");
	}
	return 0;
}

Post a Comment

0 Comments