Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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.
- 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?
- Input
- The first line of the input contains a single integer T denoting the number of test cases
- • The first line of each test case contains a single integer N. • The second line contains N space-separated integers a1, a2.... ₫
- Output
- For each test case, print "YES" if all people can be served or "NO" otherwise.*/
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- { int test_case,i,men,c_5 = 0,c_10 = 0;
- int rupee[30];
- printf("Enter number of cases: \n");
- scanf("%d",&test_case);
- while(test_case)
- {
- start: //jump level FOR GOTO FUCTION
- if(test_case == 0)
- break;
- test_case--;
- c_5 = 0,c_10 = 0;
- printf("Enter number of customer: ");
- scanf("%d",&men);
- printf("Please enter the rupee of every customer: \n");
- /*Enter all customers money in the seqence*/
- for ( i = 0; i < men; i++)
- {
- printf("Enter rupee of customer no %d: ",i+1);
- scanf("%d",&rupee[i]);
- }
- for ( i = 0; i < men; i++)
- {
- /*checking whether the first customer give more than 5 rupee*/
- if(i==0)
- {
- if(rupee[i]>5)
- {
- printf("\nNO");
- goto start;
- }
- }
- if(rupee[i] == 5)
- c_5++; //counting the 5 rupee coin that ramesh has.
- /*if customer gives either 10 or 15 rupee*/
- else if(rupee[i] > 5)
- {
- if(rupee[i] == 10)
- {
- /*If customer give 10 rupee but Ramesh has no 5 rupee to return*/
- if(c_5 == 0)
- {
- printf("\nNO");
- goto start;
- }
- else //If Ramesh has five rupee to return for
- {
- c_5--;
- c_10++;
- }
- }
- else //when rupee = 15
- {
- /*When customer gives 15 rupee but Ramesh has no 10 rupee to return*/
- if(c_10 == 0 && c_5 < 2)
- {
- printf("\nNO");
- goto start;
- }
- else if (c_10 > 0)//When Ramesh has 10 rupee coin
- c_10--;
- else //when Ramesh has more than 2 five rupee coin.
- c_5 = c_5 - 2;
- }
- }
- }//for
- printf("\nYES\n");
- }
- return 0;
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement