码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 3085 -- Quick Change

时间:2019-03-29 00:42:37      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:code   idt   store   under   ++   enter   hang   ble   WAD   

Quick Change
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6288   Accepted: 4468

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 customers. 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 should 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 should 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 customers back the smallest total number of coins. For example, if the change due back is $1.24, the customer should receive 4 quarters, 2 dimes, 0 nickels, and 4 pennies.

Input

The first line of input contains an integer which 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)

Where Q is he number of quarters, D is the number of dimes, n is the number of nickels and P is the number of pennies.

Sample Input

3
124
25
194

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

 
是一道水题8~
 
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int N;
 8     int t;
 9     int cha;
10     scanf("%d",&N);
11     t=1;
12     while(t<=N){
13             int q=0;
14             int d=0;
15             int n=0;
16             int p=0;
17             scanf("%d",&cha);
18             while(cha-25>=0){
19                 cha=cha-25;
20                 q++;
21             }
22             while(cha-10>=0){
23                 cha=cha-10;
24                 d++;
25             }
26             while(cha-5>=0){
27                 cha=cha-5;
28                 n++;
29             }
30             while(cha-1>=0){
31                 cha=cha-1;
32                 p++;
33             }
34             printf("%d %d QUARTER(S), %d DIME(S), %d NICKEL(S), %d PENNY(S)\n",t,q,d,n,p);
35             t++;
36     }
37     return 0;
38 }

错倒不是错,但是都减那么多次了,为什么就那么笨想不到除呢。

改进:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int N;
    int t;
    int cha;
    scanf("%d",&N);
    t=1;
    while(t<=N){
            scanf("%d",&cha);
            int q,d,n,p;
            q=cha/25;
            cha%=25;
            d=cha/10;
            cha%=10;
            n=cha/5;
            cha%=5;
            p=cha;
            printf("%d %d QUARTER(S), %d DIME(S), %d NICKEL(S), %d PENNY(S)\n",t,q,d,n,p);
            t++;
    }
    return 0;
}

 

POJ 3085 -- Quick Change

标签:code   idt   store   under   ++   enter   hang   ble   WAD   

原文地址:https://www.cnblogs.com/dudulukeyxian/p/10618526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!