260324 TIL - 챕터4 멀티플레이어 게임개발 12일차
2026. 3. 24. 21:56ㆍ언리얼 7기 본캠프
//순위 검색 문제
#include <string>
#include <vector>
#include <sstream>
#include <unordered_map>
#include <algorithm>
using namespace std;
unordered_map<string, vector<int>> counts;
void dfs(const vector<string>& infovec, int score, int depth, string current){
if (depth == 4)
{
counts[current].push_back(score);
return;
}
dfs(infovec, score, depth + 1, current + infovec[depth]);
dfs(infovec, score, depth + 1, current + '-');
}
void addtocounts (const string& info){
string lang, job, exp, food;
string dump;
int score;
stringstream ss(info);
ss >> lang >> job >> exp >> food >> score;
vector<string> infovec = {lang, job, exp, food};
dfs(infovec, score, 0, "");
}
vector<int> solution(vector<string> info, vector<string> query) {
vector<int> answer(query.size(), 0);
for(const string& s : info) addtocounts(s);
for(auto& pair : counts) sort(pair.second.begin(), pair.second.end());
for(int i = 0; i < query.size(); i++)
{
string lang, job, exp, food;
string dump;
int score;
stringstream ss(query[i]);
ss >> lang >> dump >> job >> dump >> exp >> dump >> food >> score;
string tosearch = lang + job + exp + food;
auto it = lower_bound(counts[tosearch].begin(), counts[tosearch].end(), score);
int index = it - counts[tosearch].begin();
answer[i] = counts[tosearch].size() - index;
}
return answer;
}'언리얼 7기 본캠프' 카테고리의 다른 글
| 260326 TIL - 챕터4 멀티플레이어 게임개발 14일차 (0) | 2026.03.26 |
|---|---|
| 260325 TIL - 챕터4 멀티플레이어 게임개발 13일차 (0) | 2026.03.25 |
| 260323 TIL - 챕터4 멀티플레이어 게임개발 11일차 (0) | 2026.03.23 |
| 260320 TIL - 챕터4 멀티플레이어 게임 개발 10일차 (0) | 2026.03.20 |
| 260319 TIL - 챕터 4 9번과제 제출일 (0) | 2026.03.19 |