标题:小白求助时间超时
只看楼主
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
结帖率:100%
 问题点数:0 回复次数:1 
小白求助时间超时
只能修改类 使时间再缩短些 谢谢
#include<iostream>
#include<stdio.h>
using namespace std;
class Time{
private:
    unsigned int h,m,s;
    static unsigned int sum;
public:
    inline Time():h(0),m(0),s(0){sum++;}

    inline Time(unsigned int hh,unsigned int mm,unsigned int ss)
    :h(hh),m(mm),s(ss){sum++;}

    inline Time(const Time &T)
    {h=T.hour();m=T.minute();s=T.second();
    sum++;
    printf("There was a call to the copy constructor :    %d,%d,%d\n",h,m,s);}

    inline Time &setTime(const Time& T)
    {h=T.hour();m=minute();s=second();
     sum++; return *this;}

    inline Time &setTime(unsigned int hh,unsigned int mm,unsigned int ss)
    {h=hh;m=mm;s=ss;return *this;}

    inline int hour()const{return h;}
    inline int minute()const{return m;}
    inline int second()const{return s;}

    inline int hour(int hh){h=hh;}
    inline int minute(int mm){m=mm;}
    inline int second(int ss){s=ss;}

    inline Time &getTime(){return *this;}

    inline Time &inputTime()
    {
       int hh,mm,ss;
       scanf("%d %d %d",&hh,&mm,&ss);
       h=hh;m=mm;s=ss;
       sum++;
       return *this;
    }

    inline void showTime()const
    {
        if(h>=24||m>=60||s>=60||h<0||m<0||s<0)
            printf("Time error\n");
        else
        {printf("%.2d:%.2d:%.2d\n",h,m,s);}
    }

    inline static int getNumber(){return sum;}
    inline static void displayNumber()
    {printf("Now, There is %d object of Time.\n",sum);}

    inline ~Time(){}
};
unsigned int Time::sum=0;

int main()
{
    cout<<"Static member test output :"<<endl;
    Time::displayNumber();
    Time t;
    t.displayNumber();
    Time tt(t);
    tt.displayNumber();
    Time ttt(1, 2, 3);
    ttt.displayNumber();
    Time tttt(ttt.getTime());
    tttt.displayNumber();
    int non_cases = Time::getNumber();

    cout<<"\nTest data output :"<<endl;
    int hour, minute, second;
    while(cin>>hour>>minute>>second)
    {
        Time t;
        t.setTime(hour, minute, second).showTime();
    }
    cout<<t.getNumber() - non_cases<<endl;
}
搜索更多相关主题的帖子: public include private 
2015-05-08 22:43
吐歌
Rank: 2
等 级:论坛游民
帖 子:43
专家分:19
注 册:2014-10-19
得分:0 
已会 加上#define while(cinhourminutesecond) while(scanf("%d%d%d",&h,&m,&s)!=EOF)

||||||||||||^_^COMEONFORGOODLIFE^_^||||||||||||
2015-05-12 18:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-445040-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016172 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved