UVa12541 - Birthdates(排序)
来源:互联网 发布:图片数据库 编辑:程序博客网 时间:2024/06/01 20:43
Write a program to identify the youngest person and the oldest person in a class.
Input
The number n (1 n 100) in the rst line determines the number of people in a class. The following
n lines contain person's name and his/her birthdate.
The information in each line is of this format:
personN ame dd mm yyyy
where personN ame is a single word less than 15 letters, dd mm yyyy are date, month and year of the
birthdate.
Suppose that no one has the same name or the same birthdate.
Output
Print out 2 lines containing the name of youngest person and oldest person, respectively.
Sample Input
5
Mickey 1 10 1991
Alice 30 12 1990
Tom 15 8 1993
Jerry 18 9 1990
Garfield 20 9 1990
Sample Output
Tom
Jerry
#include <cstdio>#include <algorithm>#include <cstring>#include <vector>#include <string>using namespace std;const int N = 20;struct Person{ string name; int year, month, day; bool operator < (const Person &other) const { if (year != other.year) return year > other.year; if (month != other.month) return month > other.month; if (day != other.day) return day > other.day; return name < other.name; }};vector<Person> persons;void input();void solve();int main(){#ifndef ONLINE_JUDGE freopen("e:\\uva_in.txt", "r", stdin);#endif input(); solve(); return 0;}void input(){ int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char name[N]; int d, m, y; scanf("%s%d%d%d", name, &d, &m, &y); persons.push_back((Person){name, y, m, d}); }}void solve(){ sort(persons.begin(), persons.end()); printf("%s\n%s\n", persons.front().name.c_str(), persons.back().name.c_str());}
0 0
- UVa12541 - Birthdates(排序)
- UVA 12541 Birthdates 解题报告
- fzu训练赛14 H - Birthdates
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- 排序
- [Python]入门教程(六):Python中的数据结构
- MFC小程序02————— 不规则窗口小应用程序
- HDU 2807 The Shortest Path(矩阵相乘+Floyd)
- lucene、solr中的日期衰减方法-------function query --尚未测试在solr4.8
- 题目1388:跳台阶
- UVa12541 - Birthdates(排序)
- Android Layout布局文件里的android:layout_height等属性为什么会不起作用?
- A - Red and Black(3.2.1)(搜索)
- [LeetCode] Implement strStr()
- 马踏棋盘(简单广搜)
- Android NDK-STACK Tool
- 遍历出基础教程视频文件夹里所有视频名称
- 黑马程序员——异常处理
- RabbitMq的配置