fork download
  1. /*
  2.  
  3. EGYPIZZA - Pizza
  4. no tags
  5.  
  6. Abotrika is having a party because his team won the african cup so he is inviting his friends to eat some pizza.
  7.  
  8. Unfortunately,Abotrika's friends can't eat an entire pizza but all of them know exactly how much pizza
  9.  
  10. they can eat and insist on getting the exact amount of pizza but Abotrika eats one complete pizza
  11. and all of them wants his amount of pizza in one slice.
  12.  
  13.  
  14. Their requests break down to three different pizza slices-either one quarter or a half or three quarters of pizza.
  15.  
  16. write a program that will help Abotrika to find out what is the minimal number of pizzas he has to order so that
  17.  
  18. everyone gets exact amount of pizza they want.
  19.  
  20. Input
  21.  
  22. First line contains an integer N, 0<=N<=10,000 , number of friends.
  23.  
  24. In each of next N lines there is amount of pizza that each of Abotrika's friends wants to eat,that
  25.  
  26. is the fraction 1/4 , 1/2 or 3/4.
  27.  
  28. Output
  29.  
  30. In the first and only line you should write the minimal number of pizzas Abotrika has order don't forget to order
  31.  
  32. one complete pizza for Abotrika
  33.  
  34. Example
  35.  
  36. Input:
  37. 3
  38.  
  39. 1/2
  40.  
  41. 3/4
  42.  
  43. 3/4
  44.  
  45. Output:
  46. 4
  47.  
  48. Input:
  49.  
  50. 5
  51.  
  52. 1/2
  53.  
  54. 3/4
  55.  
  56. 1/2
  57.  
  58. 1/4
  59.  
  60. 1/4
  61.  
  62. Output:
  63.  
  64. 4
  65.  
  66. Note : the problem rejudged
  67. */
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. #include<stdio.h>
  75. #include<string.h>
  76. #include<math.h>
  77. int min (int a , int b ){
  78. return (a<b) ? a : b ;
  79. }
  80. int main (){
  81.  
  82. int temp1 , temp = 0 , i, n , ekchar = 0 , half = 0 , tinchar = 0 , count = 0 ;
  83. char scanner[50];
  84.  
  85. scanf("%d",&n);
  86.  
  87. while(n--){
  88. scanf("%s",scanner);
  89.  
  90. if(strcmp(scanner,"1/2")==0)
  91. half++;
  92. else if(strcmp(scanner,"3/4")==0)
  93. tinchar++;
  94. else if(strcmp(scanner,"1/4")==0)
  95. ekchar++;
  96.  
  97. }
  98.  
  99. temp1 = tinchar ;
  100.  
  101. while(temp1-->0 && ekchar >0){
  102. ekchar--;
  103. // printf("ekchar");
  104. }
  105.  
  106. temp1 = half ;
  107.  
  108. while(temp1-->0 && ekchar > 1 )
  109. {
  110. ekchar = ekchar - 2 ;
  111. // printf("half balence \\ ") ;
  112. }
  113. count = tinchar + ceil(ekchar*.25) + half;
  114.  
  115.  
  116.  
  117. //printf("<ekchar - %d><tinchar - %d ><half - %d>",ekchar ,tinchar , half);
  118. printf("%d\n",count+1);
  119.  
  120.  
  121.  
  122.  
  123. return 0;
  124.  
  125. }
  126.  
Success #stdin #stdout 0s 5548KB
stdin
20
3/4
3/4
3/4
3/4
3/4
1/4
1/2 
1/2
1/2
1/2
1/2
1/2
1/4
1/4
1/4
1/4
1/4
1/4
1/4
1/4
stdout
12