zoukankan      html  css  js  c++  java
  • POJ 3085

    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)
    ",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)
    ",t,q,d,n,p);
                t++;
        }
        return 0;
    }
  • 相关阅读:
    Win Form 项目中app.config读取和修改 [ZT]
    实现全站统一的Page_PreInit()等事件
    DateTime的所有格式化输出
    大三下的半学期快过去了。。
    SQL Server 中易混淆的数据类型
    解决RD2作业在IE和Fire Fox中CSS效果不同的问题~
    AJAX也广告?
    App_Code目录下的全局类
    怀疑我不是那种材料。。
    用了几天Asp.Net 2.0遇到的几个小问题
  • 原文地址:https://www.cnblogs.com/dudulukeyxian/p/10618526.html
Copyright © 2011-2022 走看看