백준 풀이 C++

백준 5635번 c++ vector sort

ag2개발자 2022. 9. 17. 09:24
#include <bits/stdc++.h>
using namespace std;

struct stu {
	string n;
	int d, m, y;
};

bool com(const struct stu& x, const struct stu& y) {
	if (x.y < y.y) {
		return true;
	}
	else if (x.y == y.y) {
		if (x.m < y.m) {
			return true;
		}
		else if (x.m == y.m) {
			if (x.d < y.d) {
				return true;
			}
			else {
				return false;
			}

		}

		else {
			return false;
		}
	}
	else {
		return false;
	}

}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int k;
	cin >> k;
	vector<stu> arr;
	for (int i = 0; i < k; i++) {
		string s;
		int a, b, c;
		cin >> s >> a >> b >> c;
		arr.push_back({ s,a,b,c });
	}
	sort(arr.begin(), arr.end(), com);
	cout << arr[k - 1].n << "\n" << arr[0].n;
	return 0;
}

'백준 풀이 C++' 카테고리의 다른 글

백준 1427 c++ 거꾸로 sort  (0) 2022.09.19
백준 2581 C++ 소수찾기  (0) 2022.09.17
백준 1822 C++ 차집합  (0) 2022.09.16
백준 2910번 c++ map활용  (0) 2022.09.16
백준 1978 C++ (소수) (sqrt)  (0) 2022.09.04