Advertisement
Mr_kindle

RameshCoin.c

Oct 26th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.13 KB | None | 0 0
  1. /*Ramesh owns a shawarma food truck in Manila. There are only three types of coins in Manila: 5, 10 and 15. The Shawarma costs 5. There are "N" people (numbered II through N) standing in a queue to buy Shawarma from the food truck. Each person wants to buy exactly one Shawarma. For each valid i, the i-th person has one coin with value a. It is only possible for someone to buy a Shawarma when Ramesh can give them back their change exactly-for example, if someone pays with a 10 coin, Ramesh needs to have a 5 coin that he gives to that person as change.
  2.  
  3. Initially, Ramesh has no money. He wants to know if he can sell Shawarma to everyone in the queue, in the given order. Since he is busy in preparing Shawarma, can you tell him if he can serve all these people?
  4.  
  5. Input
  6.  
  7. The first line of the input contains a single integer T denoting the number of test cases
  8.  
  9. • The first line of each test case contains a single integer N. • The second line contains N space-separated integers a1, a2.... ₫
  10.  
  11. Output
  12.  
  13. For each test case, print "YES" if all people can be served or "NO" otherwise.*/
  14.  
  15.  
  16.  
  17. #include<stdio.h>
  18. #include<stdlib.h>
  19. int main()
  20. {   int test_case,i,men,c_5 = 0,c_10 = 0;
  21.     int rupee[30];
  22.     printf("Enter number of cases: \n");
  23.     scanf("%d",&test_case);
  24.    
  25.     while(test_case)
  26.         {    
  27.             start: //jump level FOR GOTO FUCTION
  28.            
  29.             if(test_case == 0)
  30.             break;
  31.  
  32.             test_case--;
  33.             c_5 = 0,c_10 = 0;
  34.             printf("Enter number of customer:  ");
  35.             scanf("%d",&men);
  36.             printf("Please enter the rupee of every customer: \n");
  37.             /*Enter all customers money in the seqence*/
  38.             for ( i = 0; i < men; i++)
  39.             {
  40.                 printf("Enter rupee of customer no %d: ",i+1);
  41.                 scanf("%d",&rupee[i]);
  42.             }
  43.            
  44.             for ( i = 0; i < men; i++)
  45.             {
  46.                 /*checking whether the first customer give more than 5 rupee*/
  47.                 if(i==0)
  48.                     {
  49.                         if(rupee[i]>5)
  50.                             {
  51.                                 printf("\nNO");
  52.                                 goto start;
  53.                             }
  54.                        
  55.                     }
  56.                 if(rupee[i] == 5)
  57.                     c_5++; //counting the 5 rupee coin that ramesh has.
  58.                    
  59.                    /*if customer gives either 10 or 15 rupee*/
  60.                 else if(rupee[i] > 5)
  61.                     {
  62.                         if(rupee[i] == 10)
  63.                             {  
  64.                                 /*If customer give 10 rupee but Ramesh has no 5 rupee to return*/
  65.                                 if(c_5 == 0)
  66.                                     {
  67.                                         printf("\nNO");
  68.                                         goto start;
  69.                                     }
  70.                                 else //If Ramesh has five rupee to return for
  71.                                     {
  72.                                         c_5--;
  73.                                         c_10++;
  74.                                     }
  75.                             }
  76.                         else //when rupee = 15
  77.                             {  
  78.                                 /*When customer gives 15 rupee but Ramesh has no 10 rupee to return*/
  79.                                 if(c_10 == 0 && c_5 < 2)
  80.                                     {
  81.                                         printf("\nNO");
  82.                                         goto start;
  83.                                     }
  84.                                 else if (c_10 > 0)//When Ramesh has 10 rupee coin
  85.                                     c_10--;
  86.                                 else //when Ramesh has more than 2 five rupee coin.
  87.                                     c_5 = c_5 - 2;
  88.                             }
  89.                     }
  90.  
  91.                    
  92.                
  93.             }//for
  94.            
  95.            
  96.             printf("\nYES\n");
  97.            
  98.         }
  99.        
  100.         return 0;
  101. }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement