Pokeball - Pokemon

99클럽 TIL

99클럽 코테 스터디 27일차 TIL + 기타(C++)

ansi. 2024. 11. 24. 01:03

문제

[백준] 11557번: Yangjojang of The Year

https://www.acmicpc.net/problem/11557

 

코드

#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

        int T;
        cin >> T;

        while (T--) {
            int N;
            cin >> N;

            string max_S = "";
            int max_L = 0;

            for (int i = 0; i < N; i++) {
                string S;
                int L;

                cin >> S >> L;

                if (L > max_L) {
                    max_S = S;
                    max_L = L;
                }
            }

            cout << max_S << '\n';
        }

    return 0;
}

 

풀이

SL을 입력받을 때마다 max_LL을 비교해, L > max_L 이면 max_Smax_L을 갱신한다.

각 테스트 케이스가 끝날 때마다 max_S을 출력