###### 编程介的小学生

2017-06-08 13:36 阅读 813

# Who is Older?

Javaman and cpcs are arguing who is older. Write a program to help them.

Input

There are multiple test cases. The first line of input is an integer T (0 < T <= 1000) indicating the number of test cases. Then T test cases follow. The i-th line of the next T lines contains two dates, the birthday of javaman and the birthday of cpcs. The format of the date is "yyyy mm dd". You may assume the birthdays are both valid.

Output

For each test case, output who is older in a single line. If they have the same birthday, output "same" (without quotes) instead.

Sample Input

3
1983 06 06 1984 05 02
1983 05 07 1980 02 29
1991 01 01 1991 01 01
Sample Output

javaman
cpcs
same

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享

#### 1条回答默认 最新

• 已采纳
love1code 2017-06-08 14:29
``````#include <iostream>
#include <cstdlib>
#include <cassert>

using namespace std;
class Birthday
{
private:
int year;
int month;
int day;
public:

friend std::istream& operator>> (std::istream& in , Birthday& bir);
enum{ OLDER = 1, YOUNGER = 2 , SAME = 3 };

Birthday():year(1970),month(1),day(1)
{
}

int compare(const Birthday& bir) const
{
if      (year < bir.year) return OLDER;
else if (year > bir.year) return YOUNGER;
else
{
if(month < bir.month) return OLDER;
else if (month > bir.month) return YOUNGER;
else
{
if(day < bir.day) return OLDER;
else if (day > bir.day) return YOUNGER;
else
return SAME;
}
}
}

};

std::istream& operator>> (std::istream& in , Birthday& bir)
{
in>>bir.year
>>bir.month
>>bir.day;
return in;
}

int main()
{

Birthday javaman,cpcs;
int T;
cin>>T;
for(int i=0;i<T;++i)
{
cin>>javaman;
cin>>cpcs;

int c = javaman.compare(cpcs);

if(c == Birthday::OLDER) cout<<"javaman"<<endl;
else if(c==Birthday::YOUNGER) cout<<"cpcs"<<endl;
else cout<<"same"<<endl;

}

return 0;
}
``````
点赞 评论 复制链接分享