#include<iostream>
#include<string>
using namespace std;
class Time_12hours;
class Time_24hours;
class Time
{
public:
virtual bool operator > (Time_12hours&)=0;
virtual bool operator > (Time_24hours&)=0;
virtual bool operator ==(Time_12hours&)=0;
virtual bool operator ==(Time_24hours&)=0;
virtual bool operator <(Time_12hours&)=0;
virtual bool operator <(Time_24hours&)=0;
virtual void display()=0;
int second;
int minute;
int hour;
};
class Time_12hours: public Time
{
public:
Time_12hours():type("12-hours-time"),interval("AM"){}
void set_date();
void set_interval_1(){interval="AM";}
//用于主函数里的判断,给interval赋值
void set_interval_2(){interval="PM";}
//用于主函数里的判断,给interval赋值
virtual bool operator>(Time_12hours&);
virtual bool operator>(Time_24hours&);
virtual bool operator==(Time_12hours&);
virtual bool operator==(Time_24hours&);
virtual bool operator<(Time_12hours&);
virtual bool operator<(Time_24hours&);
virtual void display();
string interval;
//标识为AM或者PM,interval=”AM”或interval=”PM”
private:
string type;
//标识为12进制时间,type=”12-hours-time”
};
void Time_12hours::set_date()
{
cin>>hour>>minute>>second;
}
bool Time_12hours::operator>(Time_12hours& t1)
{
if(interval==t1.interval)
{
if(hour>t1.hour){return true;}
else if(hour<t1.hour){return false;}
else if(minute>t1.minute){return true;}
else if(minute<t1.minute){return false;}
else if(second>t1.second){return true;}
else if(second>=t1.second){return false;}
}
else if(interval=="PM"){return true;}
else {return false;}
}
bool Time_12hours::operator>(Time_24hours& t2)
{
int j;
if(interval=="AM")j=0;
else j=1;
switch(j)
{
case 0:{hour=hour+12;}
case 1:
{
if(hour>t2.hour){return true;}
else if(hour<t2.hour){return false;}
else if(minute>t2.minute){return true;}
else if(minute<t2.minute){return false;}
else if(second>t2.second){return true;}
else if(second>=t2.second){return false;}
}
}
}
bool Time_12hours::operator==(Time_12hours& t1)
{
if(interval==t1.interval)
{
if(hour==t1.hour)
{
if(minute==t1.minute)
{
if(second==t1.second)
{
return true;
}
else return false;
}
else return false;
}
else return false;
}
else return false;
}
bool Time_12hours::operator==(Time_24hours& t2)
{
switch(interval)
{
case "PM":{hour=hour+12;}
case "AM":
{
if(hour==t1.hour)
{
if(minute==t1.minute)
{
if(second==t1.second)
{
return true;
}
else return false;
}
else return false;
}
else return false;
}
}
}
bool Time_12hours::operator<(Time_12hours& t1)
{
if(interval==t1.interval)
{
if(hour<t1.hour){return true;}
else if(hour>t1.hour){return false;}
else if(minute<t1.minute){return true;}
else if(minute>t1.minute){return false;}
else if(second<t1.second){return true;}
else if(second>=t1.second){return false;}
}
else if(interval=="AM"){return true;}
else {return false;}
}
bool Time_12hours::operator<(Time_24hours& t2)
{
switch(interval)
{
case "PM":{hour=hour+12;}
case "AM":
{
if(hour<t1.hour){return true;}
else if(hour>t1.hour){return false;}
else if(minute<t1.minute){return true;}
else if(minute>t1.minute){return false;}
else if(second<t1.second){return true;}
else if(second>=t1.second){return false;}
}
}
}
void Time_12hours::display()
{
cout<<interval<<" ";
if(hour<10)
cout<<"0"<<hour<<":";
else
cout<<hour<<":";
if(minute<10)
cout<<"0"<<minute<<":";
else
cout<<minute<<":";
if(second<10)
cout<<"0"<<second<<endl;
else
cout<<second<<endl;
}
class Time_24hours: public Time
{
public:
Time_24hours():type("24-hours-time"){}
void set_date();
virtual bool operator>(Time_12hours&);
virtual bool operator>(Time_24hours&);
virtual bool operator==(Time_12hours&);
virtual bool operator==(Time_24hours&);
virtual bool operator<(Time_12hours&);
virtual bool operator<(Time_24hours&);
virtual void display();
private:
string type;
//标识为24进制时间,type=”24-hours-time”
};
void Time_24hours::set_date()
{
cin>>hour>>minute>>second;
}
bool Time_24hours::operator>(Time_12hours& t1)
{
int j;
if(t1.interval=="PM")j=1;
else j=0;
switch(j)
{
case 1:{hour=hour+12;}
case 0:
{
if(hour>t1.hour){return true;}
else if(hour<t1.hour){return false;}
else if(minute>t1.minute){return true;}
else if(minute<t1.minute){return false;}
else if(second>t1.second){return true;}
else if(second>=t1.second){return false;}
}
}
}
bool Time_24hours::operator>(Time_24hours& t2)
{
if(hour>t2.hour){return true;}
else if(hour<t2.hour){return false;}
else if(minute>t2.minute){return true;}
else if(minute<t2.minute){return false;}
else if(second>t2.second){return true;}
else if(second>=t2.second){return false;}
}
bool Time_24hours::operator==(Time_12hours& t1)
{
int j;
if(t1.interval=="PM")j=1;
else j=0;
switch(j)
{
case 1:{hour=hour+12;}
case 0:
{
if(hour==t1.hour)
{
if(minute==t1.minute)
{
if(second==t1.second)
{
return true;
}
else return false;
}
else return false;
}
else return false;
}
}
}
bool Time_24hours::operator==(Time_24hours& t2)
{
if(hour==t2.hour)
{
if(minute==t2.minute)
{
if(second==t2.second)
{
return true;
}
else return false;
}
else return false;
}
else return false;
}
bool Time_24hours::operator<(Time_12hours& t1)
{
int j;
if(t1.interval=="PM")j=1;
else j=0;
switch(j)
{
case 1:{hour=hour+12;}
case 0:
{
if(hour<t1.hour){return true;}
else if(hour>t1.hour){return false;}
else if(minute<t1.minute){return true;}
else if(minute>t1.minute){return false;}
else if(second<t1.second){return true;}
else if(second>=t1.second){return false;}
}
}
}
bool Time_24hours::operator<(Time_24hours& t2)
{
{
if(hour<t2.hour){return true;}
else if(hour>t2.hour){return false;}
else if(minute<t2.minute){return true;}
else if(minute>t2.minute){return false;}
else if(second<t2.second){return true;}
else if(second>=t2.second){return false;}
}
}
void Time_24hours::display()
{
if(hour<10)
cout<<"0"<<hour<<":";
else
cout<<hour<<":";
if(minute<10)
cout<<"0"<<minute<<":";
else
cout<<minute<<":";
if(second<10)
cout<<"0"<<second<<endl;
else
cout<<second<<endl;
}
int main()
{
Time *time1,*time2;
Time_12hours t1,t2;
Time_24hours t3,t4;
int n;
//需要比较的时间组数
int j;
//选择时间种类
cin>>n;
//输入需要比较的时间组数
for(;n>0;n--)
{
cin>>j;
switch(j)
{
case 121:{t1.set_interval_1();t1.set_date();time1=&t1;}break;
case 122:{t1.set_interval_2();t1.set_date();time1=&t1;}break;
case 24:{t3.set_date();time1=&t3;}break;
}
cin>>j
switch(j)
{
case 121:{t2.set_interval_1();t2.set_date();time2=&t1;}break;
case 122:{t2.set_interval_2();t2.set_date();time2=&t1;}break;
case 24:{t4.set_date();time1=&t4;}break;
}
if(*time1<*time2)
{
cout<<"time1";
time1->display();
cout<<"<";
time2->display();
}
else if(*time1>*time2)
{
cout<<"time1";
time1->display();
cout<<">";
time2->display();
}
else if(*time1==*time2)
{
cout<<"time1";
time1->display();
cout<<"==";
time2->display();
}
else
{
cout<<"There is something wrong with the input."
<<"Please check it!"<<endl;
}
}
return 0;
}