알고리즘 연습

C++11098 첼시를 도와줘

728x90

#include <iostream>
#include <vector>;
#include <string>;
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	while (n--) {
		int t;
		cin >> t;
		int max = 0;
		vector<pair<int, string>> c(t);
		string maxName;

		for (int i = 0; i < t; i++) {
			cin >> c[i].first >> c[i].second;
			if (max < c[i].first) {
				max = c[i].first;
				maxName = c[i].second;
			}			
		}
		cout << maxName << '\n';
	}
}

처음에는 sort를 이용해서 c [0]. second를 출력하면 될 줄 알았는데 작동이 되지 않았다.

그래서 그냥 최댓값을 구하고 그의 이름을 출력하는 방식으로 진행했다.

728x90

'알고리즘 연습' 카테고리의 다른 글

C++ 2442 별찍기 5  (0) 2021.10.17
C++ 10984 내학점을 구해줘  (0) 2021.10.15
C++ 1977 완전제곱수  (0) 2021.10.11
C++ 1541 잃어버린 괄호  (0) 2021.10.07
C++ 1931 회의실 배정  (0) 2021.10.07