#include <vector>
#include <string>
#include <unordered_map>
using namespace std;
unordered_map <string, string> unParent = {};
unordered_map <string, int> unProfits = {};
void updateProfit(string sName, int iMoney)
{
// 부모의 이름이 없거나 돈이 끝이라면 끝
if (sName == "-" || !iMoney)
return;
int iCharge = iMoney * 0.1;
// 부모에게 10퍼의 돈만 넣기
unProfits[sName] += iMoney - iCharge;
// 재귀
updateProfit(unParent[sName], iCharge);
}
vector<int> solution(vector<string> enroll, vector<string> referral,
vector<string> seller, vector<int> amount)
{
vector<int> answer;
// 부모 연결
for (int i = 0; i < referral.size(); i++)
{
unParent[enroll[i]] = referral[i];
}
// 수익 연결
for (int i = 0; i < seller.size(); i++)
{
updateProfit(seller[i], amount[i] * 100);
}
// 정답 연결
for (int i = 0; i < enroll.size(); i++)
{
answer.push_back(unProfits[enroll[i]]);
}
return answer;
}
unordered map이 pair가 안통하길래 vector로 사용했더니 시간이... 재귀를 사용하는 방법이 있었네...
그리고 젤 중요한 것 int로 변환해야한다. 0.1곱하기만 하고 round를 썻더니 테케는 성공하는데 다른건 계속 실패해서 이유를 몰라서 헤맸다 진짜 엄청...
'오늘의 알고리즘' 카테고리의 다른 글
| [C++]2019 KAKAO BLIND RECRUITMENT후보키(프로그래머스2레벨) (0) | 2022.03.13 |
|---|---|
| [C++]2021 KAKAO BLIND RECRUITMENT순위 검색(프로그래머스 2레벨) (0) | 2022.03.11 |
| [C++]2017 팁스타운예상 대진표(프로그래머스 2레벨) (0) | 2022.03.09 |
| [C++]찾아라 프로그래밍 마에스터게임 맵 최단거리(프로그래머스 2레벨) (0) | 2022.03.08 |
| [C++]그래프 순위(프로그래머스 3레벨) (0) | 2022.03.07 |