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;
    }
  • 相关阅读:
    C#语法造成的小问题(编译原理知识)
    COM套间对.NET程序使用COM对象的影响
    为什么连接字符串一定要用StringBuilder(介绍CLR Profiler)
    编译原理系列文章
    .NET与COM互操作系列
    Windows XP SidebySide功能对VC程序的影响
    引起FileNotFoundException原因通用分析过程
    Flex组件的项目渲染器(ItemRenderer)使用总结
    Flex组件开发总结20090209
    如何去掉超链接图片外蓝色的边框
  • 原文地址:https://www.cnblogs.com/dudulukeyxian/p/10618526.html
Copyright © 2011-2022 走看看