한국어< 中文 فارسی English ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin
#include <iostream> #include <iomanip> #include <sstream> using namespace std; class Time { private: int h,m,s; public: Time():h(0),m(0),s(0){} Time(int hh,int mm,int ss) : h(hh),m(mm),s(ss){} Time(const Time &t) { h = t.h;m = t.m;s = t.s; } public: Time &inputTime() { int hour, minute, second; cin>>hour>>minute>>second; this->hour(hour);this->minute(minute);this->second(second); return *this; } public: void hour(int hh){ h = hh;} void minute(int mm){ m = mm;} void second(int ss ){ s = ss;} public: int hour()const{return h;} int minute()const{return m;} int second()const{return s;} public: void showTime() const { if(h >= 0&& h<24 && m >=0 && m < 60 && s >= 0 && s < 60){ cout << setw(2) << setfill('0'); cout << setw(2) << h << ":"; cout << setw(2) << m << ":"; cout << setw(2) << s; } else cout << "Time error"; } public: Time & operator++() { if(h >= 0&&h < 24&&m >= 0&&m < 60 && s >= 0 &&s < 60) { s++; while (s >= 60 ) { s -= 60; m++; } while (m >= 60 ) { m -= 60; h++; } while (h >= 24 ) { h -= 24; } } return *this; } const Time operator++(int) { Time t(*this); if(h >= 0&&h < 24&&m >= 0&&m < 60 && s >= 0 &&s < 60) { s++; while (s >= 60 ) { s -= 60; m++; } while (m >= 60 ) { m -= 60; h++; } while (h >= 24 ) { h -= 24; } } return t; } Time & operator--() { if(h >= 0&&h < 24&&m >= 0&&m < 60 && s >= 0 &&s < 60) { s --; while ( s < 0 ) { s += 60; m--; } while ( m < 0 ) { m += 60; h--; } while ( h < 0 ) { h += 24; } } return *this; } const Time operator--(int) { Time t(*this); if(h >= 0&&h < 24&&m >= 0&&m < 60 && s >= 0 &&s < 60) { s--; while ( s < 0 ) { s += 60; m--; } while ( m < 0 ) { m += 60; h--; } while ( h < 0 ) { h += 24; } } return t; } friend istream &operator>>(istream &is,Time &t) { is >> t.h >> t.m >> t.s; return is; } friend ostream &operator<<(ostream &os,const Time &t) { if(t.h >= 0&& t.h<24 && t.m >=0 && t.m < 60 && t.s >= 0 && t.s < 60){ cout << setw(2) << setfill('0'); cout << setw(2) << t.h << ":"; cout << setw(2) << t.m << ":"; cout << setw(2) << t.s; } else cout << "error!!!"; return os; } }; 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; cout<<(++t)<<" "; cout<<(--t)<<" "; cout<<t<<" "; cout<<t--<<" "; cout<<t++<<" "; cout<<t<<endl; } }