|
|
back to boardNo subject #include <iostream> #include <cstring> #include <algorithm> using namespace std; struct Date { int day;
int month;
int year; }; struct person { int num;
int live;
Date die; }; bool comp(person a, person b) { if (a.live != b.live) return a.live > b.live; if (a.die.year != b.die.year) return a.die.year < b.die.year; if (a.die.month != b.die.month) return a.die.month < b.die.month; if (a.die.day != b.die.day) return a.die.day < b.die.day; } bool leap(int year) { if (year%400==0) return 1; if (year%100==0) return 0; if (year%4==0) return 1; else return 0; } int monthDay(int year, int month) { if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) return 31;
else if (month == 4 || month == 6|| month == 9 || month == 11) return 30;
else if (leap(year))return 29;
else return 28; } int Distance(Date a, Date b)//a??¨®¨²b o??e¨º?¨®????1¨¨??¨² { int dis = 0;
for (int i = a.year+1; i < b.year; ++i) { if (leap(i)) dis += 366;
else dis += 365; }
if (a.year != b.year) { for (int i = a.month+1; i <= 12; ++i) { dis += monthDay(a.year, i); }
dis += (monthDay(a.year, a.month) - a.day + 1); for (int i = 1; i < b.month; ++i) { dis += monthDay(b.year, i); }
dis += b.day; } else { if (a.month != b.month) { dis += (monthDay(a.year, a.month) - a.day + 1);cout << monthDay(a.year, a.month) << endl;
for (int i = a.month+1; i < b.month; ++i) { dis += monthDay(b.year, i); }
dis += b.day; } else { dis += (b.day - a.day + 1); } }
return dis; } int convert(char a, char b) { return (a - '0')*10 + b - '0'; } int convert(char a, char b, char c, char d) { return (a - '0')*1000 + (b - '0')*100 + (c - '0')*10 + d - '0'; } void print(Date a) { cout << a.year << " " << a.month << " " << a.day << endl; } int main() { int m;
cin >> m;
char useless[11];
Date a, b;
person p[101];
for (int i = 0; i < m; ++i) { scanf("%d.%d.%d", &a.day, &a.month, &a.year);
cin >> useless;
scanf("%d.%d.%d", &b.day, &b.month, &b.year);
p[i].num = i+1; p[i].live = Distance(a, b);
p[i].die = b; }
sort(p, p+m, comp);
cout << p[0].num << endl;
system("pause"); } Re: No subject I don't know why it always gets wrong answer; Re: No subject i know………… it's my fault... because i cout more sth. |
|
|