zoukankan      html  css  js  c++  java
  • [YTU]_2633( P3 数钱是件愉快的事)

    题目描述

    超市收银员的钱盒里,各种钞票总是按照面额分类整理,这样做可以提高效率,保证工作质量。
    我们就要制造这个分面额整理钞票的钱盒。为简单起见,只支持百元、拾元和壹元三种纸币。一个钱盒中有4张百元、16张拾元、14张一元钞票,没错,一共574元;另一个钱盒中,12张百元、17张拾元、9张一元钞票,你知道有多少元;将这两个钱盒中的钞票放在同一个盒子里,嘿嘿,这是件愉快的事。
    下面的程序,就完成这件事。不过,设计师写好了类声明,测试员做好了测试函数,钱盒的功能,体现为Money类的构造函数,就等着程序员你来完成了。
    请在begin到end部分写上你该实现的函数,并提交这一部分代码。
    #include<iostream>
    using namespace std;
    class Money
    {
    private:
        int hundred;   //百元张数
        int ten;       //拾百元张数
        int one;       //壹元张数
    public:
        Money(int h=0,int t=0, int o=0);
        Money operator+(const Money &m);
        friend ostream &operator<<(ostream &out,Money m);
    };
    //************* begin *****************
    //************* end *****************
    int main()
    {
        int mh1, mt1, mo1, mh2, mt2,mo2;
        cin>>mh1>>mt1>>mo1;
        cin>>mh2>>mt2>>mo2;
        Money m1(mh1, mt1, mo1), m2(mh2, mt2,mo2);
        cout<<m1<<endl;
        cout<<m2<<endl;
        Money m3;
        m3=m1+m2;
        cout<<m3<<endl;
        return 0;
    }

    输入

    2行,每行3个数字,分别表示2个钱盒中百、拾、壹元钞票的张数

    输出

    输出3行,分别表示前面输入的2个钱盒的情况,以及将2个钱盒相加后的情况
    每个钱盒的输出格式是:
    总面额<-->百元张数*100+拾元张数*10+壹元张数

    样例输入

    4 16 14
    12 17 9

    样例输出

    574<-->4*100+16*10+14
    1379<-->12*100+17*10+9
    1953<-->16*100+33*10+23
    #include<iostream>
    using namespace std;
    class Money
    {
    private:
        int hundred;   //百元张数
        int ten;       //拾百元张数
        int one;       //壹元张数
    public:
        Money(int h=0,int t=0, int o=0);
        Money operator+(const Money &m);
        friend ostream &operator<<(ostream &out,Money m);
    };Money::Money(int h,int t,int o)
    {
        hundred=h;
        ten=t;
        one=o;
    }
    Money Money::operator +(const Money &m)
    {return Money(hundred+m.hundred,ten+m.ten,one+m.one);}
    ostream &operator<<(ostream &out,Money m)
    {
        out<<m.hundred*100+m.ten*10+m.one<<"<-->"<<m.hundred<<"*100+"<<m.ten<<"*10+"<<m.one;
        return out;
    }
    int main()
    {
        int mh1, mt1, mo1, mh2, mt2,mo2;
        cin>>mh1>>mt1>>mo1;
        cin>>mh2>>mt2>>mo2;
        Money m1(mh1, mt1, mo1), m2(mh2, mt2,mo2);
        cout<<m1<<endl;
        cout<<m2<<endl;
        Money m3;
        m3=m1+m2;
        cout<<m3<<endl;
        return 0;
    }

  • 相关阅读:
    [Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F
    [Codeforces Round #611 (Div. 3)] C. Friends and Gifts (随机大法好)
    [Hello 2020] D. New Year and Conference (ST表,排序)
    [Hello 2020] C. New Year and Permutation (组合数学)
    Codeforces Beta Round #7 C. Line (扩展欧几里德)
    扩展欧几里德
    Codeforces Round #349 (Div. 2) D. World Tour (最短路)
    HDU 4052 Adding New Machine (线段树+离散化)
    HDU 3265 Posters (线段树+扫描线)(面积并)
    HDU 1828 Picture (线段树+扫描线)(周长并)
  • 原文地址:https://www.cnblogs.com/sxy201658506207/p/7586339.html
Copyright © 2011-2022 走看看