#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){ *this=rhs; }
public:
int hour(){return h_;}
int hour(int h){return h_=h;}
int minute(){return m_;}
int minute(int m){return m_=m;}
int second(){return s_;}
int second(int s){return s_=s;}
public:
Time& setTime(int h,int m,int s){ h_=h; m_=m; s_=s; return *this; }
Time& setTime(const Time& rhs) { h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; return *this; }
Time& getTime() { return *this; }
public:
Time& inputTime(){
cin>>h_>>m_>>s_;
return *this;
}
void showTime12Hour() const {
if(h_==0&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_+12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>=13&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_-12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>0&&h_<=12&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; }
if(h_>=12) cout<<" p.m."; else cout<<" a.m."; cout<<endl;
}
void showTime() const {
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; } cout<<endl;
}
};
int main()
{
cout<<"Constant test output :"<<endl;
const Time c(11, 59, 58);
const Time cc(12, 0, 1);
c.showTime12Hour();
cc.showTime12Hour();
c.showTime();
cc.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.showTime12Hour();
}
if(i % 4 == 1)
{
int hour, minute, second;
cin>>hour>>minute>>second;
t.setTime(hour, minute, second).showTime();
}
if(i % 4 == 2)
t.inputTime().showTime12Hour();
if(i % 4 == 3)
{
int hour, minute, second;
cin>>hour>>minute>>second;
t.hour(hour);
t.minute(minute);
t.second(second);
t.showTime();
}
}
}
2
#include<bits/stdc++.h>
using namespace std;
class Time{
private:
int h_,m_,s_;
static int tol;
public:
Time():h_(0),m_(0),s_(0) { tol++; }
Time(int h,int m,int s):h_(h),m_(m),s_(s) { tol++; }
Time(const Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; tol++; }
Time(Time& rhs){ *this=rhs; tol++;
cout<<"There was a call to the copy constructor : "<<rhs.h_<<','<<rhs.m_<<','<<rhs.s_<<endl;
}
public:
int hour(){return h_;}
int hour(int h){return h_=h;}
int minute(){return m_;}
int minute(int m){return m_=m;}
int second(){return s_;}
int second(int s){return s_=s;}
public:
Time& setTime(int h,int m,int s){ h_=h; m_=m; s_=s; return *this; }
Time& setTime(const Time& rhs) { h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; return *this; }
Time& getTime() { return *this; }
public:
Time& inputTime(){
cin>>h_>>m_>>s_;
return *this;
}
void showTime12Hour() const {
if(h_==0&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_+12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>=13&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_-12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>0&&h_<=12&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; }
if(h_>=12) cout<<" p.m."; else cout<<" a.m."; cout<<endl;
}
void showTime() const {
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; } cout<<endl;
}
public:
static void displayNumber(){
cout<<"Now, There is "<<tol<<" object of Time."<<endl;
}
static int getNumber(){
return tol;
}
};
int Time::tol=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;
}
3
#include<bits/stdc++.h>
using namespace std;
class Time{
private:
int h_,m_,s_;
static int tol;
public:
Time():h_(0),m_(0),s_(0) { tol++; }
Time(int h,int m,int s):h_(h),m_(m),s_(s) { tol++; }
Time(const Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; tol++; }
Time(Time& rhs){ *this=rhs; tol++;
// cout<<"There was a call to the copy constructor : "<<rhs.h_<<','<<rhs.m_<<','<<rhs.s_<<endl;
}
public:
int hour(){return h_;}
int hour(int h){return h_=h;}
int minute(){return m_;}
int minute(int m){return m_=m;}
int second(){return s_;}
int second(int s){return s_=s;}
public:
Time& setTime(int h,int m,int s){ h_=h; m_=m; s_=s; return *this; }
Time& setTime(const Time& rhs) { h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; return *this; }
Time& getTime() { return *this; }
public:
Time& inputTime(){
cin>>h_>>m_>>s_;
return *this;
}
void showTime12Hour() const {
if(h_==0&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_+12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>=13&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_-12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>0&&h_<=12&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; }
if(h_>=12) cout<<" p.m."; else cout<<" a.m."; cout<<endl;
}
void showTime() const {
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; } cout<<endl;
}
public:
static void displayNumber(){
cout<<"Now, There is "<<tol<<" object of Time."<<endl;
}
static int getNumber(){
return tol;
}
friend Time& operator += (Time &tmp,int num){
if(tmp.h_>=0&&tmp.h_<=23&&tmp.m_>=0&&tmp.m_<60&&tmp.s_<60&&tmp.s_>=0){
tmp.s_+=num;
tmp.m_+=(tmp.s_/60);
tmp.s_%=60;
tmp.h_+=(tmp.m_/60);
tmp.m_%=60;
tmp.h_%=24;
}
else return tmp;
}
friend Time& operator -= (Time &tmp,int num){
if(tmp.h_>=0&&tmp.h_<=23&&tmp.m_>=0&&tmp.m_<60&&tmp.s_<60&&tmp.s_>=0){
tmp.s_-=num;
tmp.m_+=(tmp.s_/60);
if(tmp.s_ < 0 && tmp.s_ >-60) tmp.m_ -=1;
(tmp.s_+=60)%=60;
tmp.h_+=(tmp.m_/60);
if(tmp.m_ < 0 && tmp.m_ >-60) tmp.h_ -=1;
(tmp.m_+=60)%=60;
(tmp.h_+=24)%=24;
}
else return tmp;
}
};
int Time::tol=0;
int main()
{
int cases;
cin>>cases;
for(int i = 1; i <= cases; ++i)
{
Time t;
t.inputTime();
Time tt(t);
int num;
cin>>num;
t += num;
t.showTime();
tt -= num;
tt.showTime();
}
}
#include<bits/stdc++.h>
using namespace std;
class Time{
private:
int h_,m_,s_;
static int tol;
public:
Time():h_(0),m_(0),s_(0) { tol++; }
Time(int h,int m,int s):h_(h),m_(m),s_(s) { tol++; }
Time(const Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; tol++; }
Time(Time& rhs){ *this=rhs; tol++;
// cout<<"There was a call to the copy constructor : "<<rhs.h_<<','<<rhs.m_<<','<<rhs.s_<<endl;
}
public:
int hour(){return h_;}
int hour(int h){return h_=h;}
int minute(){return m_;}
int minute(int m){return m_=m;}
int second(){return s_;}
int second(int s){return s_=s;}
public:
Time& setTime(int h,int m,int s){ h_=h; m_=m; s_=s; return *this; }
Time& setTime(const Time& rhs) { h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; return *this; }
Time& getTime() { return *this; }
public:
Time& inputTime(){
cin>>h_>>m_>>s_;
return *this;
}
void showTime12Hour() const {
if(h_==0&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_+12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>=13&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_-12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>0&&h_<=12&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; }
if(h_>=12) cout<<" p.m."; else cout<<" a.m."; cout<<endl;
}
void showTime() const {
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; } cout<<endl;
}
public:
static void displayNumber(){
cout<<"Now, There is "<<tol<<" object of Time."<<endl;
}
static int getNumber(){
return tol;
}
friend Time& operator += (Time &tmp,int num){
if(tmp.h_>=0&&tmp.h_<=23&&tmp.m_>=0&&tmp.m_<60&&tmp.s_<60&&tmp.s_>=0){
while(num--){
if(tmp.s_!=59){
tmp.s_++;
}else {
if(tmp.m_!=59){
tmp.m_++;
tmp.s_=0;
}
else {
tmp.h_++;
if(tmp.h_==24) tmp.h_=0;
tmp.m_=0;
tmp.s_=0;
}
}
}
}
else return tmp;
}
friend Time& operator -= (Time &tmp,int num){
if(tmp.h_>=0&&tmp.h_<=23&&tmp.m_>=0&&tmp.m_<60&&tmp.s_<60&&tmp.s_>=0){
while(num--){
if(tmp.s_!=0){
tmp.s_--;
}else {
if(tmp.m_!=0){
tmp.m_--;
tmp.s_=59;
}
else {
tmp.h_--;
if(tmp.h_<0) tmp.h_=23;
tmp.m_=59;
tmp.s_=59;
}
}
}
}
else return tmp;
}
};
int Time::tol=0;
int main()
{
int cases;
cin>>cases;
for(int i = 1; i <= cases; ++i)
{
Time t;
t.inputTime();
Time tt(t);
int num;
cin>>num;
t += num;
t.showTime();
tt -= num;
tt.showTime();
}
}
4
#include<bits/stdc++.h>
using namespace std;
class Time{
private:
int h_,m_,s_;
static int tol;
public:
Time():h_(0),m_(0),s_(0) { tol++; }
Time(int h,int m,int s):h_(h),m_(m),s_(s) { tol++; }
Time(const Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; tol++; }
Time(Time& rhs){ *this=rhs; tol++;
// cout<<"There was a call to the copy constructor : "<<rhs.h_<<','<<rhs.m_<<','<<rhs.s_<<endl;
}
public:
int hour(){return h_;}
int hour(int h){return h_=h;}
int minute(){return m_;}
int minute(int m){return m_=m;}
int second(){return s_;}
int second(int s){return s_=s;}
public:
Time& setTime(int h,int m,int s){ h_=h; m_=m; s_=s; return *this; }
Time& setTime(const Time& rhs) { h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; return *this; }
Time& getTime() { return *this; }
public:
Time& inputTime(){
cin>>h_>>m_>>s_;
return *this;
}
void showTime12Hour() const {
if(h_==0&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_+12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>=13&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_-12<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else if(h_>0&&h_<=12&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; }
if(h_>=12) cout<<" p.m."; else cout<<" a.m."; cout<<endl;
}
void showTime() const {
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
cout<<setw(2)<<setfill('0')<<h_<<':'<<setw(2)<<setfill('0')<<m_<<':'<<setw(2)<<setfill('0')<<s_;
else { cout<<"Time error\n"; return ; } cout<<endl;
}
public:
static void displayNumber(){
cout<<"Now, There is "<<tol<<" object of Time."<<endl;
}
static int getNumber(){
return tol;
}
friend Time& operator += (Time &tmp,int num){
if(tmp.h_>=0&&tmp.h_<=23&&tmp.m_>=0&&tmp.m_<60&&tmp.s_<60&&tmp.s_>=0){
while(num--){
if(tmp.s_!=59){
tmp.s_++;
}else {
if(tmp.m_!=59){
tmp.m_++;
tmp.s_=0;
}
else {
tmp.h_++;
if(tmp.h_==24) tmp.h_=0;
tmp.m_=0;
tmp.s_=0;
}
}
}
}
else return tmp;
}
friend Time& operator -= (Time &tmp,int num){
if(tmp.h_>=0&&tmp.h_<=23&&tmp.m_>=0&&tmp.m_<60&&tmp.s_<60&&tmp.s_>=0){
while(num--){
if(tmp.s_!=0){
tmp.s_--;
}else {
if(tmp.m_!=0){
tmp.m_--;
tmp.s_=59;
}
else {
tmp.h_--;
if(tmp.h_<0) tmp.h_=23;
tmp.m_=59;
tmp.s_=59;
}
}
}
}
else return tmp;
}
friend istream& operator >> (istream& in,Time& rhs){
in >> rhs.h_ >>rhs.m_ >>rhs.s_;
return in;
}
friend ostream& operator << (ostream& out,Time& rhs){
if(rhs.h_>=0&&rhs.h_<=23&&rhs.m_>=0&&rhs.m_<60&&rhs.s_<60&&rhs.s_>=0)
out<<setw(2)<<setfill('0')<<rhs.h_<<':'<<setw(2)<<setfill('0')<<rhs.m_<<':'<<setw(2)<<setfill('0')<<rhs.s_;
else { out<<"error!!!"; }
return out;
}
public:
Time& operator++ (){
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
if(++s_ ==60){
if(++m_==60){
if(++h_==24) h_=0;
m_=0;
}
s_=0;
}
return *this;
}
Time& operator++ (int){
int h=h_;
int m=m_;
int s=s_;
Time t(h,m,s);
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
if(++s_ ==60){
if(++m_==60){
if(++h_==24) h_=0;
m_=0;
}
s_=0;
}
return t;
}
Time& operator-- (){
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
if(--s_ <0){
if(--m_<0){
if(--h_<0) h_=23;
m_=59;
}
s_=59;
}
return *this;
}
Time& operator-- (int){
int h=h_;
int m=m_;
int s=s_;
Time t(h,m,s);
if(h_>=0&&h_<=23&&m_>=0&&m_<60&&s_<60&&s_>=0)
if(--s_ <0){
if(--m_<0){
if(--h_<0) h_=23;
m_=59;
}
s_=59;
}
return t;
}
};
int Time::tol(0);
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;
}
}
5
#include<bits/stdc++.h>
using namespace std;
map<string,string> M;
int main()
{
ios::sync_with_stdio(false);
int t;
while(cin>>t){
M.clear();
while(t--){
string s1,s2;
cin>>s1>>s2;
M[s2]=s1;
}
int n;
cin>>n;
while(n--){
string s;
cin>>s;
if(M.count(s)){
cout<<M[s]<<endl;
}else cout<<"eh"<<endl;
}
}
return 0;
}
6
#include<bits/stdc++.h>
using namespace std;
map<string,int> M;
int main()
{
ios::sync_with_stdio(false);
int t;
while(cin>>t){
M.clear();
while(t--){
string s; int x;
cin>>s>>x;
M[s]=x;
}
for(map<string,int>::iterator it=M.begin();it!=M.end();it++)
{
cout<<it->first<<":"<<it->second<<endl;
}
}
return 0;
}
7
#include<bits/stdc++.h>
using namespace std;
string x[55000];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
cin>>x[i];
sort(x,x+n);
for(int i=0;i<n;i++)
cout<<x[i]<<endl;
return 0;
}
6万+

被折叠的 条评论
为什么被折叠?



