B1028. 人口普查
基本思路
- 定义一个结构体person,persion的属性是姓名和生日
- 生日用年、月、日来表示
- 合法性判断(左右边界判断),先检查年,再检查月,最后检查日
#include <bits/stdc++.h> using namespace std; struct Person { char name[10]; int yy, mm, dd; }youngest, oldest, left_p, right_p, temp; void init() { youngest.yy = left_p.yy = 1814; youngest.mm = left_p.mm = 9; youngest.dd = left_p.dd = 6; oldest.yy = right_p.yy = 2014; oldest.mm = right_p.mm = 9; oldest.dd = right_p.dd = 6; } bool younger(Person person, Person target) { if (person.yy != target.yy) { return person.yy < target.yy; } if (person.mm != person.mm) { return person.mm < target.mm; } if (person.dd != person.dd) { return person.dd < target.dd; } return false; } bool older(Person person, Person target) { if (person.yy != target.yy) { return person.yy > target.yy; } if (person.mm != person.mm) { return person.mm > target.mm; } if (person.dd != person.dd) { return person.dd > target.dd; } return false; } int main(int argc, char* argv[]) { init(); int N, yy, mm, dd, num = 0; cin >> N; for (int i = 0; i < N; i++) { scanf("%s %d/%d/%d", temp.name, &temp.yy, &temp.mm, &temp.dd); if (younger(temp, right_p) && older(temp, left_p)) { num++; if (younger(youngest, temp)) { youngest = temp; } if (older(oldest, temp)) { oldest = temp; } } } cout << num << ' ' << oldest.name << ' ' << youngest.name << ' ' << endl; return 0; }
论读书
睁开眼,书在面前 闭上眼,书在心里
睁开眼,书在面前 闭上眼,书在心里