 # CUPCONE - Editorial

https://www.codechef.com/RSC2017/problems/CUPCONE

Author: spraveenkumar

CAKEWALK

Math

### PROBLEM:

Chef visits an ice cream shop. The ice creams came as Cylindrical cups and Cones. Surprisingly both cost the same. Chef being a great lover of ice cream, wants the one with maximum volume.
You are given the radius and heights of the cup and cone. Output which has the most volume of ice cream. In case of cone, output “CONE”. For Cup, output “CUP”. If both had the same volume, output “ANY”, all without quotes.

### QUICK EXPLANATION:

This is just as simple as comparing the volume of Cylinder, PIrrh with Volume of cone, (PIrrh)/3

### EXPLANATION:

You are given the radius and height of the cylindrical cup and cone. You can use a simple if statement to compare the volumes. The volume of a cylinder is calculated by the formula, PI x r2 x h and that of a cone by ( PI x r2 x h ) /3 By substituting the radius and height of the cylinder and cone in respective formula, we can find the volume and compare them in a single step. As PI is constant and present in both, for comparison, it can be, but necessarily need to be, cancelled.

O(1)

### AUTHOR’s SOLUTION:

``````
import java.util.Scanner;
class Icecream{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t= sc.nextInt();
while(t-- != 0){
int coneR = sc.nextInt();
int coneH = sc.nextInt();
int cupR = sc.nextInt();
int cupH = sc.nextInt();
float rConeVol = ((float)(coneR*coneR*coneH))/3;	//relative cone volume
float rCupVol = cupR*cupR*cupH;
if(rConeVol>rCupVol)
System.out.println("CONE");
else if(rConeVol<rCupVol)
System.out.println("CUP");
else
System.out.println("ANY");
}
sc.close();
}
}

``````
//