setw(w) :設置數據的輸出寬度為w個字符
setfill(c):設置用字符c作為填充字符
한국어<
中文
فارسی
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> using namespace std; class Time{ private: int h,m,s; public: Time(int hh,int mm,int ss):h(hh),m(mm),s(ss){} void showTime(){cout<<setw(2)<<setfill('0')<<h<<":"<<setw(2)<<setfill('0')<<m<<":"<<setw(2)<<setfill('0')<<s<<endl;} }; int main() { int cases; cin>>cases; for(int i = 1; i <= cases; ++i) { int hour, minute, second; cin>>hour>>minute>>second; Time t(hour, minute, second); t.showTime(); } }
Home Web Board ProblemSet Standing Status Statistics Problem B: 時間類的成員讀寫
setw(w) :設置數據的輸出寬度為w個字符
setfill(c):設置用字符c作為填充字符
한국어<
中文
فارسی
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> using namespace std; class Time{ private: int h,m,s; public: Time(){} int hour(){return h;} int minute(){return m;} int second(){return s;} void hour(int hh){h=hh;} void minute(int mm){m=mm;} void second(int ss){s=ss;} }; int main() { Time t; int cases; cin>>cases; for(int i = 1; i <= cases; ++i) { int hour, minute, second; cin>>hour>>minute>>second; t.hour(hour); t.minute(minute); t.second(second); cout<<setw(2)<<setfill('0')<<t.hour()<<":"; cout<<setw(2)<<setfill('0')<<t.minute()<<":"; cout<<setw(2)<<setfill('0')<<t.second()<<endl; } }
Home Web Board ProblemSet Standing Status Statistics Problem C: 時間類的輸入
setw(w) :設置數據的輸出寬度為w個字符
setfill(c):設置用字符c作為填充字符
한국어<
中文
فارسی
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> using namespace std; class Time{ private: int h,m,s; public: Time(){} Time& inputTime(){cin>>h>>m>>s;return *this;} void showTime(){cout<<setw(2)<<setfill('0')<<h<<":"<<setw(2)<<setfill('0')<<m<<":"<<setw(2)<<setfill('0')<<s<<endl;} }; int main() { Time t; int cases; cin>>cases; for(int i = 1; i <= cases; ++i) t.inputTime().showTime(); }
Home Web Board ProblemSet Standing Status Statistics Problem D: 時間類的拷貝和整體讀寫
setw(w) :設置數據的輸出寬度為w個字符
setfill(c):設置用字符c作為填充字符
한국어<
中文
فارسی
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> 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;cout<<"There was a call to the copy constructor : "<<h<<","<<m<<","<<s<<endl;} Time& setTime(int hh,int mm,int ss){h=hh;m=mm;s=ss;return *this;} Time& setTime(const Time&T){h=T.h;m=T.m;s=T.s;return *this;} Time& getTime(){return *this;} void showTime(){cout<<setw(2)<<setfill('0')<<h<<":"<<setw(2)<<setfill('0')<<m<<":"<<setw(2)<<setfill('0')<<s<<endl;} }; int main() { cout<<"Copy constructor test output :"<<endl; Time t; Time tt(t); Time ttt(1, 2, 3); Time tttt(ttt.getTime()); cout<<"\nTest data output :"<<endl; int cases; cin>>cases; for(int i = 1; i <= cases; ++i) { if(i % 2 == 0) { int hour, minute, second; cin>>hour>>minute>>second; t.setTime(hour, minute, second).showTime(); } if(i % 2 == 1) { int hour, minute, second; cin>>hour>>minute>>second; Time tt(hour, minute, second); t.setTime(tt).showTime(); } } }
Home Web Board ProblemSet Standing Status Statistics Problem E: 時間類的錯誤數據處理
setw(w) :設置數據的輸出寬度為w個字符
setfill(c):設置用字符c作為填充字符
한국어<
中文
فارسی
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> 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;cout<<"There was a call to the copy constructor : "<<h<<","<<m<<","<<s<<endl;} int hour(){return h;} int minute(){return m;} int second(){return s;} void hour(int hh){h=hh;} void minute(int mm){m=mm;} void second(int ss){s=ss;} Time& setTime(int hh,int mm,int ss){h=hh;m=mm;s=ss;return *this;} Time& setTime(const Time&T){h=T.h;m=T.m;s=T.s;return *this;} Time& getTime(){return *this;} Time& inputTime(){cin>>h>>m>>s;return *this;} void showTime(){if(h*3600+m*60+s>=24*3600||m>59||s>59||h<0||s<0||m<0) cout<<"Time error"<<endl; else cout<<setw(2)<<setfill('0')<<h<<":"<<setw(2)<<m<<":"<<setw(2)<<s<<endl;} }; int main() { Time t; int cases; cin>>cases; for(int i = 1; i <= cases; ++i) { if(i % 4 == 0) { int hour, minute, second; cin>>hour>>minute>>second; Time tt(hour, minute, second); tt.showTime(); } if(i % 4 == 1) { int hour, minute, second; cin>>hour>>minute>>second; t.setTime(hour, minute, second).showTime(); } if(i % 4 == 2) t.inputTime().showTime(); if(i % 4 == 3) { int hour, minute, second; cin>>hour>>minute>>second; t.hour(hour); t.minute(minute); t.second(second); t.showTime(); } } }
Home Web Board ProblemSet Standing Status Statistics Problem F: 時間類的常量
setw(w) :設置數據的輸出寬度為w個字符
setfill(c):設置用字符c作為填充字符
한국어<
中文
فارسی
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> 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;cout<<"There was a call to the copy constructor : "<<h<<","<<m<<","<<s<<endl;} int hour()const{return h;} int minute()const{return m;} int second()const{return s;} void hour(int hh){h=hh;} void minute(int mm){m=mm;} void second(int ss){s=ss;} Time& setTime(int hh,int mm,int ss){h=hh;m=mm;s=ss;return *this;} Time& setTime(const Time&T){h=T.h;m=T.m;s=T.s;return *this;} const Time& getTime()const{return *this;} Time& inputTime(){cin>>h>>m>>s;return *this;} void showTime()const{if(h*3600+m*60+s>=24*3600||m>59||s>59||h<0||s<0||m<0) cout<<"Time error"<<endl; else cout<<setw(2)<<setfill('0')<<h<<":"<<setw(2)<<m<<":"<<setw(2)<<s<<endl;} }; int main() { cout<<"Constant test output :"<<endl; const Time c; const Time cc(1, 2, 3); const Time ccc(23, 60, 60); cout<<setw(2)<<setfill('0')<<c.hour()<<":"; cout<<setw(2)<<setfill('0')<<c.minute()<<":"; cout<<setw(2)<<setfill('0')<<c.second()<<endl; cc.getTime().showTime(); ccc.showTime(); cout<<"\nTest data output :"<<endl; Time t; int cases; cin>>cases; for(int i = 1; i <= cases; ++i) { if(i % 4 == 0) { int hour, minute, second; cin>>hour>>minute>>second; Time tt(hour, minute, second); tt.showTime(); } if(i % 4 == 1) { int hour, minute, second; cin>>hour>>minute>>second; t.setTime(hour, minute, second).showTime(); } if(i % 4 == 2) t.inputTime().showTime(); if(i % 4 == 3) { int hour, minute, second; cin>>hour>>minute>>second; t.hour(hour); t.minute(minute); t.second(second); t.showTime(); } } }