완주하지 못한 선수

#include <string>
#include <vector>
#include <unordered_map>

using namespace std;
unordered_map<string, int> um;

string solution(vector<string> participant, vector<string> completion) {
    string answer = "";
    
    for (int i = 0; i < completion.size(); i++) {
        if (um.find(completion[i]) == um.end()) { // 못찾을때
            um.insert(make_pair(completion[i], 1));
        } else {
            um[completion[i]]++;
        }
    }
    
    for (auto j : participant) {
        if (um.find(j) == um.end()) { //못찾으면
            answer = j;
            break;
        } else {
            um[j]--;
            if (um[j] < 0) {
                answer = j;
                break;
            }
        }
    }
    
    
    return answer;
}

K번째수

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

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    
    for (int i = 0; i < commands.size(); i++) {
        vector<int> clone;
        
        for (int j = commands[i][0] - 1; j <= commands[i][1] - 1; j++) {
            clone.push_back(array[j]);
        }
        sort(clone.begin(), clone.end());
        int ret = clone[commands[i][2]-1];
        answer.push_back(ret);
    }
    
    return answer;
}
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    vector<int> clone;
    
    for (int i = 0; i < commands.size(); i++) {
        clone = array;
        
        sort(clone.begin() + commands[i][0]-1,
             clone.begin() + commands[i][1]);
        int ret = clone[commands[i][0] - 1 + commands[i][2] - 1];
        answer.push_back(ret);
    }
    
    return answer;
}

신고결과받기

#include <string>
#include <sstream>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

vector<int> solution(vector<string> id_list, vector<string> report, int k) {
    // 1. 자료구조
    vector<int> answer(id_list.size(), 0);
    unordered_map<string, unordered_set<string>> reports;
    unordered_map<string, int> reported_count;
    
    // 2. 신고 정보 처리
    for (auto r : report) {
        stringstream iss(r);
        string reporter, reported;
        iss >> reporter >> reported;
        
        if (reports[reporter].insert(reported).second) {
            reported_count[reported]++;
        }
    }
    
    // 3. 결과 계산
    for (int i=0; i<id_list.size(); i++) {
        for (auto reported : reports[id_list[i]]) {
            if (reported_count[reported] >= k) {
                answer[i]++;
            }
        }
    }
    return answer;
}