POJ 3085 Quick Change (Greedy)

Source: Internet
Author: User

POJ 3085 Quick Change (Greedy)
Quick Change

Time Limit:1000 MS Memory Limit:65536 K
Total Submissions:5801 Accepted:4175

Description

J.P. flathead's Grocery Store hires cheap labor to man the checkout stations. the people he hires (usually high school kids) often make mistakes making change for the MERs. flathead, who's a bit of a tightwad, figures he loses more money from these mistakes than he makes; that is, the employees tend to give more change to the customers than they shocould get.

Flathead wants you to write a program that calculates the number of quarters ($0.25), dimes ($0.10), nickels ($0.05) and pennies ($0.01) that the customer shocould get back. flathead always wants to give the customer's change in coins if the amount due back is $5.00 or under. he also wants to give the MERs back the smallest total number of coins. for example, if the change due back is $1.24, the customer shocould receive 4 quarters, 2 dimes, 0 nickels, and 4 pennies.

Input

The first line of input contains an integerNWhich is the number of datasets that follow. Each dataset consists of a single line containing a single integer which is the change due in cents,C, (1 ≤C ≤ 500 ).

Output

For each dataset, print out the dataset number, a space, and the string:

Q QUARTER(S), D DIME(S), N NICKEL(S), P PENNY(S)

WhereQIs he number of quarters,DIs the number of dimes,NIs the number of nickels andPIs the number of pennies.

Sample Input

312425194

Sample Output

1 4 QUARTER(S), 2 DIME(S), 0 NICKEL(S), 4 PENNY(S)2 1 QUARTER(S), 0 DIME(S), 0 NICKEL(S), 0 PENNY(S)3 7 QUARTER(S), 1 DIME(S), 1 NICKEL(S), 4 PENNY(S)

Source

Greater New York 2006 is looking for change. Code: # include
# Include
# Include
Using namespace std;
Int main ()
{
Int n, m, I;
Int f [4] = {25, 10, 5, 1 };
While (scanf ("% d", & n )! = EOF & n)
{
For (I = 1; I <= n; I ++)
{
Int k [4] = {0 };
Scanf ("% d", & m );
While (m> = f [0]) {m-= f [0]; k [0] ++ ;}
While (m> = f [1]) {m-= f [1]; k [1] ++ ;}
While (m> = f [2]) {m-= f [2]; k [2] ++ ;}
While (m> = f [3]) {m-= f [3]; k [3] ++ ;}
Printf ("% d QUARTER (S), % d DIME (S), % d NICKEL (S), % d PENNY (S) \ n", I, k [0], k [1], k [2], k [3]);
}
}
Return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.