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;
    }
  • 相关阅读:
    SQL SERVER CXPACKET-Parallelism Wait Type 的惯用解决方案
    服务器主体 "sa" 无法在当前安全上下文下访问数据库 XXX[SQLSTATE 08004] (错误 916). 该步骤失败。
    Android 使用 aapt 命令查看 apk 包名
    Android数据库GreenDao的使用总结
    NestedScrollView、ScrollView 加载完自动滑动至底部问题的解决方案
    Android框架式编程之Retrofit
    Visual Studio 开发(三):Visual Studio 使用时常见问题解决方案
    Android 网络交互之移动端与服务端的加密处理
    Android框架式编程之ViewModel
    Android框架式编程之LiveData
  • 原文地址:https://www.cnblogs.com/dudulukeyxian/p/10618526.html
Copyright © 2011-2022 走看看