小白求助时间超时
只能修改类 使时间再缩短些 谢谢#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;
}