728x90
https://www.acmicpc.net/problem/5635
5635번: 생일
어떤 반에 있는 학생들의 생일이 주어졌을 때, 가장 나이가 적은 사람과 가장 많은 사람을 구하는 프로그램을 작성하시오.
www.acmicpc.net
문제 요약
학생들의 생일이 주어졌을 때, 가장 나이가 적은 사람과 가장 많은 사람을 구하라.
//1015번: 수열 정렬
#include <iostream>
#include <algorithm>
using namespace std;
typedef struct Student{
string name;
int dd, mm, yy;
}Student;
bool compare(const Student s1, const Student s2){
if(s1.yy == s2.yy){
if(s1.mm == s2.mm) return s1.dd < s2.dd;
return s1.mm < s2.mm;
}
return s1.yy < s2.yy;
}
int main() {
ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
int n;
cin >> n;
Student s[n];
for(int i=0; i<n; i++) cin >> s[i].name >> s[i].dd >> s[i].mm >> s[i].yy;
sort(s, s+n, compare);
cout << s[n-1].name << '\n' << s[0].name << '\n';
return 0;
}
💡공부 및 기록용 블로그이므로 오류가 있을 수 있습니다.💡
만약 문제에 오류나 오타가 있다면 댓글로 알려주세요➿
언제나 환영합니다. 감사합니다. 화이팅!
728x90
'알고리즘 > 백준' 카테고리의 다른 글
[c++] 5800번: 성적 통계 (0) | 2022.01.14 |
---|---|
[c++] 1755번: 숫자놀이 (0) | 2022.01.14 |
[c++] 1940번: 주몽 (0) | 2022.01.14 |
[c++] 17266번: 어두운 굴다리 (0) | 2022.01.13 |
[c++] 13702번: 이상한 술집 (0) | 2022.01.13 |