fork download
  1. //Coded by Vishal Mourya
  2. //If you use this code anywhere you need to mention my name as above
  3.  
  4. /* package whatever; // don't place package name! */
  5.  
  6. import java.util.*;
  7. import java.lang.*;
  8. import java.io.*;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11.  
  12. //Note : If you are running this code on codechef then replace Ideone with Codechef
  13. class Ideone //Codechef
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. try{
  19. //write your code here
  20. Scanner sc = new Scanner(System.in);
  21. int t = sc.nextInt();
  22. while(t > 0) {
  23. int a = sc.nextInt(); //The choice input of cup or cone
  24. int n = sc.nextInt(); //number of scoops
  25.  
  26. int cost = 0;
  27. //find total cost
  28. if( a == 1 ) cost += 7; //cup
  29. else cost += 10; //cone
  30.  
  31. for( int i = 1 ; i <= n ; i++ ) {
  32. int f = sc.nextInt(); //Flavour of scoop
  33. switch(f){
  34. case 1: //Strawberry
  35. cost += 30;
  36. break;
  37. case 2: //Vanilla
  38. cost += 20;
  39. break;
  40. case 3: //Mango
  41. cost += 30;
  42. break;
  43. case 4: //Oreo
  44. cost += 50;
  45. break;
  46. case 5: //Chocolate
  47. cost += 40;
  48. break;
  49. }//end of switch
  50. }//end of for loop
  51.  
  52. if( n > 3 ){//as number of scoops cannot exceed 3
  53. System.out.println("Invalid Entry");
  54. t--;
  55. continue;
  56. }
  57. System.out.println(cost);
  58.  
  59.  
  60. t--;
  61. }//end of test case loop
  62.  
  63. }
  64. catch(Exception e){
  65.  
  66. }
  67.  
  68. }
  69. }
Success #stdin #stdout 0.12s 34612KB
stdin
2
1
3
2 2 4
2
4
1 2 3 4
stdout
97
Invalid Entry