A改错题--销售部的打印机

A改错题--销售部的打印机

时间: 1ms        内存:128M

描述:

销售部新进了一台快速打印机,使用频率很高。为了能够对打印情况进行统计,规定每个人在打印后需要登记时间和用纸张数。

注:本题只需要提交修改和完善部分的代码,请按照C++方式提交。

#include <iostream>
using namespace std;
class FastPrinter
{
public:
    FastPrinter() {}
    FastPrinter(int year,int month,int day,int num);
    ~FastPrinter() {}
    void PrintJob() {}
    static unsigned int getcounts()
    {
        return counts;
    }
    static unsigned int gettotals()
    {
        return totals;
    }
private:
    static unsigned int counts;
    static unsigned int totals;
    int year,month,day;
};
/* 修改和完善该部分代码
unsigned int FastPrinter::counts = 0;
FastPrinter::FastPrinter(int year,int month,int day,int num):year(year),month(month),day(day)
{
    totals++;
}
*/
int main()
{
    FastPrinter *fp;
    int year,month,day,num;
    int n,m;
    cin>>n;
    while(n--)
    {
        cin>>m;
        while(m--)
        {
            cin>>year>>month>>day>>num;
            fp=new FastPrinter(year,month,day,num);
            fp->PrintJob();
            delete fp;
        }
    }
    cout<<"打印次数:"<<FastPrinter::getcounts()<<",张数:"<<FastPrinter::gettotals()<<endl;
    return 0;
}

输入:

第一行n表示下面n个部门
第二行开始分别为每个部门的数据
对于每个部门,
    第一行m表示该部门打印的次数
    接来下m行给出打印的时间(年月日)和打印张数

输出:

总的打印次数和打印张数

示例输入:

3
2
2015 5 30 98
2015 6 2 128
4
2015 5 29 120
2015 6 1 1000
2015 6 3 45
2015 6 7 300
1
2015 6 3 78

示例输出:

打印次数:7,张数:1769

提示:

参考答案(内存最优[1500]):


#include <iostream>
using namespace std;
class FastPrinter
{
public:
    FastPrinter() {}
    FastPrinter(int year,int month,int day,int num);
    ~FastPrinter() {}
    void PrintJob() {}
    static unsigned int getcounts()
    {
        return counts;
    }
    static unsigned int gettotals()
    {
        return totals;
    }
private:
    static unsigned int counts;
    static unsigned int totals;
    int year,month,day;
};
unsigned int FastPrinter::counts = 0;
unsigned int FastPrinter::totals = 0;
FastPrinter::FastPrinter(int year,int month,int day,int num):year(year),month(month),day(day)
{
    counts++;
    totals+=num;
}
int main()
{
    FastPrinter *fp;
    int year,month,day,num;
    int n,m;
    cin>>n;
    while(n--)
    {
        cin>>m;
        while(m--)
        {
            cin>>year>>month>>day>>num;
            fp=new FastPrinter(year,month,day,num);
            fp->PrintJob();
            delete fp;
        }
    }
    cout<<"打印次数:"<<FastPrinter::getcounts()<<",张数:"<<FastPrinter::gettotals()<<endl;
    return 0;
}

参考答案(时间最优[0]):


#include <iostream>
using namespace std;
class FastPrinter
{
public:
    FastPrinter() {}
    FastPrinter(int year,int month,int day,int num);
    ~FastPrinter() {}
    void PrintJob() {}
    static unsigned int getcounts()
    {
        return counts;
    }
    static unsigned int gettotals()
    {
        return totals;
    }
private:
    static unsigned int counts;
    static unsigned int totals;
    int year,month,day;
};
unsigned int FastPrinter::counts = 0;
unsigned int FastPrinter::totals = 0;
FastPrinter::FastPrinter(int year,int month,int day,int num):year(year),month(month),day(day)
{
    counts++;
    totals+=num;
}
int main()
{
    FastPrinter *fp;
    int year,month,day,num;
    int n,m;
    cin>>n;
    while(n--)
    {
        cin>>m;
        while(m--)
        {
            cin>>year>>month>>day>>num;
            fp=new FastPrinter(year,month,day,num);
            fp->PrintJob();
            delete fp;
        }
    }
    cout<<"打印次数:"<<FastPrinter::getcounts()<<",张数:"<<FastPrinter::gettotals()<<endl;
    return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注