POJ 3085 -- Quick Change

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

Greater New York 2006

是一道水题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;
}

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

时间: 2024-10-11 05:46:18

POJ 3085 -- Quick Change的相关文章

POJ 3085 Quick Change (贪心)

Quick Change Time Limit: 1000MS   Memory Limit: 65536K 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 mistak

POJ Charlie&#39;s Change 查理之转换(多重背包,微变形)

题意:给定身上的4种硬币,分别是1 ,5 ,10, 25面额各有多张,要求组成面额p的硬币尽可能多.输出组成p的4种硬币各自的数量. 思路:多重背包,300+ms.用01背包+二进制的方法.记录下所有的硬币的个数以及4种硬币分别的个数,注意初始化dp数组的不同之处. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define LL long long 5 using namespace

POJ 2581 Exact Change Only(dp)

Language: Default Exact Change Only Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2584   Accepted: 883 Description Boudreaux reached over and shook awake Thibodeaux, who had dozed off somewhere in New Mexico. "Where we at?" Thibod

poj 2581 Exact Change Only (dp)

 Description Boudreaux reached over and shook awake Thibodeaux, who had dozed off somewhere in New Mexico. "Where we at?" Thibodeaux groggily yawned. "Not in Vegas, I gua-ran-tee, but could you get my knapsack?" Boudreaux asked, gest

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

UVALive 7352 Dance Recital

题意: 有n种舞蹈要跳 每种舞蹈需要每一行字符串所对应的那些人 如果一个人连着跳两个舞蹈 那么需要一个quick change 问需要的最少quick changes是多少 思路: 假期的题 又拿出来做一遍…… 范围很感人10*26 这不暴力搜一发还等啥呢…… 1 /* *********************************************** 2 Author :SunYuefeng 3 Created Time :2016/10/16 20:17:34 4 File Na

PatentTips - Fast awake from low power mode

BACKGROUND Electronic devices, such as electronic book readers ("eBook reader devices"), cellular telephones, portable media players, desktop computers, laptops, tablet computers, netbooks, personal digital assistants, and the like, rely on elec

macbook pro install ubuntu

https://help.ubuntu.com/community/MacBookPro Determine your hardware revision To determine which version / generation of MacBook Pro you have, you have multiple options: From the GUI in OS X Click on the Apple on the top left > "About this Mac&quo

Using APIs in Your Ethereum Smart Contract with Oraclize

Homepage Coinmonks HOMEFILTER ▼BLOCKCHAIN TUTORIALSCRYPTO ECONOMYTOP READSCONTRIBUTEFORUM & JOBS Go to the profile of Matt Solomon Matt Solomon Apr 20 Getting data from an outside source onto the blockchain is a non-trivial problem, and one solution