코딩테스트 연습 > 2024 KAKAO WINTER INTERNSHIP > 가장 많이 받은 선물
10/10

코딩테스트 연습 > 2022 KAKAO BLIND RECRUITMENT > 신고 결과 받기
이거랑 비슷한 느낌으로 풀면 될거같음.
프로그래머스 | 신고 결과 받기 :: 우리집강아지귀엽죠
프로그래머스 | 신고 결과 받기
코딩테스트 연습 > 2022 KAKAO BLIND RECRUITMENT > 신고 결과 받기10/10문제 이해 + 전체적인 풀이 흐름 구상 정리#include #include #include #include using namespace std;vector solution(vector id_list, vector report, int k) { mapm; /
baba-sun.tistory.com
문제 이해 + 전체적인 풀이 흐름 구상 정리


#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int solution(vector<string> friends, vector<string> gifts) {
map<string, int> m; // friends의 이름별로 번호를 매겨서 map에 저장
for(int i =0; i<friends.size(); i++) m[friends[i]] = i;
vector<vector<int>>v(friends.size(), vector<int>(friends.size(), 0));
// 주고받은거 기록용 vector
vector<int>total(friends.size(), 0); // 선물지수 count용
for(auto r : gifts){
for(int i =0; i<r.size(); i++){
if(r[i] == ' '){
int p1 = m[r.substr(0, i)]; // 선물 준사람
int p2 = m[r.substr(i+1, r.size())]; // 선물 받은사람
v[p1][p2]++; // 주고받은거 count
total[p1]++; total[p2]--; // 선물지수 준사람은++ 받은사람은--;
break;
}
}
}
vector<int>cnt(friends.size(),0); //다음 달에 받을 선물 개수 vector
for(int i =0; i<cnt.size()-1; ++i){
for(int j =i+1; j<cnt.size(); ++j){
if(v[i][j] != v[j][i]) v[i][j] > v[j][i]? cnt[i]++:cnt[j]++;
else if(total[i] != total[j]) total[i] > total[j] ? cnt[i]++:cnt[j]++;
}
}
partial_sort(cnt.begin(), cnt.begin()+1, cnt.end(), greater());
return cnt[0];
}

성공☆
'C++ 문제풀기 > 백준-프로그래머스' 카테고리의 다른 글
| 프로그래머스 | 구명보트 (0) | 2025.10.28 |
|---|---|
| 프로그래머스 | 카펫 (0) | 2025.10.28 |
| 프로그래머스 | 신고 결과 받기 (0) | 2025.10.12 |
| 백준 | 1929. 소수 구하기 (0) | 2025.10.08 |
| 백준 | 11726. 2xn 타일 (0) | 2025.10.08 |