Created
October 22, 2014 10:40
-
-
Save lexdene/4e4cf7a8ea974c56a695 to your computer and use it in GitHub Desktop.
zhihu question 26161075 code by lexdene
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Date | |
{ | |
public: | |
Date(int y=0, int m=0, int d=0):year(y), month(m), day(d){} | |
friend bool operator>(const Date& da, const Date& db); | |
int getyear()const; | |
int getmonth()const; | |
int getday()const; | |
private: | |
int year; | |
int month; | |
int day; | |
}; | |
int fake_number(const Date& da){ | |
return da.getyear() * 400 * 40 + da.getmonth() * 40 + da.getday(); | |
} | |
bool operator>(const Date& da, const Date& db){ | |
return fake_number(da) > fake_number(db); | |
} | |
int Date::getyear()const{ | |
return year; | |
} | |
int Date::getmonth()const{ | |
return month; | |
} | |
int Date::getday()const{ | |
return day; | |
} | |
int main(){ | |
Date a(2014, 10, 22), b(2015, 1, 2); | |
cout << (a > b) << endl; | |
cout << (b > a) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment