#include<bits/stdc++.h>
using namespace std;
class Time
{
private:
int h_,m_,s_;
public:
Time():h_(0),m_(0),s_(0) { }
Time(int h,int m,int s):h_(h),m_(m),s_(s) { }
Time(const Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; }
Time(Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; }
Time& operator = (Time& x){ *this=x; return x; }
~Time() {}
Time& operator++()
{
int n;
if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
else
{
n=h_*60*60+m_*60+s_;
n+=1;
if(n>=24*60*60)
{
n-=24*60*60;
h_=n/60/60%24;
m_=n/60%60;
s_=n%60;
}
else
{
h_=n/60/60%24;
m_=n/60%60;
s_=n%60;
}
}
return *this;
}
/*
Time& operator++(int)
{
//Time p(*this);
int a=h_;
int b=m_;
int c=s_;
// cout<<a<<b<<c<<endl;
// int n;
// if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
// else
// {
// n=h_*60*60+m_*60+s_;
// n+=1;
// if(n>=24*60*60)
// {
// n-=24*60*60;
// h_=n/60/60%24;
// m_=n/60%60;
// s_=n%60;
// }
// else
// {
// h_=n/60/60%24;
// m_=n/60%60;
// s_=n%60;
// }
// }
Time t(a,b,c);
// cout<<endl<<p.h_<<p.m_<<p.s_<<endl;
return t;
}
*/
Time& operator ++(int){
Time t=*this;
return t;
}
Time& operator--()
{
int n;
if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
else
{n=h_*3600+m_*60+s_;
n-=1;
if(n<0)
{
n+=86400;
h_=n/3600%24;
m_=n/60%60;
s_=n%60;
}
else
{
h_=n/3600%24;
m_=n/60%60;
s_=n%60;
}
}
return *this;
}
Time& operator--(int)
{
//Time p(*this);
int a,b,c;
a=h_;b=m_;c=s_;
Time p(a,b,c);
// int n;
// if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
// else
// {n=h_*3600+m_*60+s_;
// n-=1;
// if(n<0)
// {
// n+=86400;
// h_=n/3600%24;
// m_=n/60%60;
// s_=n%60;
// }
// else
// {
// h_=n/3600%24;
// m_=n/60%60;
// s_=n%60;
// }
// }
return p;
}
friend istream& operator >> (istream& in,Time& x){
in>>x.h_>>x.m_>>x.s_;
return in;
}
friend ostream& operator << (ostream& out,Time& x){
cout<<"********"<<x.h_<<"___"<<x.m_<<"____"<<x.s_<<"*********"<<endl;
if(x.h_>=0&&x.h_<=23&&x.m_>=0&&x.m_<=59&&x.s_>=0&&x.s_<=59)
out<<setw(2)<<setfill('0')<<x.h_<<":"<<setw(2)<<setfill('0')<<x.m_<<":"<<setw(2)<<setfill('0')<<x.s_;
else out<<"error!!!";
return out;
}
};
int main()
{
Time t;
int cases;
cin>>cases;
cout<<setw(8)<<left<<"++t"<<" ";
cout<<setw(8)<<left<<"--t"<<" ";
cout<<setw(8)<<left<<"t"<<" ";
cout<<setw(8)<<left<<"t--"<<" ";
cout<<setw(8)<<left<<"t++"<<" ";
cout<<setw(8)<<left<<"t"<<right<<endl;
for(int i = 1; i <= cases; ++i)
{
cin>>t;
Time c = t;
cout<<"&&&"<<c<<"&&"<<endl;
// cout<<(++t)<<" ";
// cout<<(--t)<<" ";
// cout<<t<<" ";
// cout<<t--<<" ";
cout<<"**"<<t++<<"*** ";
// cout<<t<<endl;
}
}
引用传递出现错误
最新推荐文章于 2022-07-01 11:14:30 发布