웅재의 코딩세상
[프로그래머스] PCCE 기출문제 8번 본문
- 풀이
#include <string>
#include <vector>
using namespace std;
string solution(vector<string> storage, vector<int> num) {
int num_item = 0;
vector<string> clean_storage(storage.size());
vector<int> clean_num(num.size());
for(int i=0; i<storage.size(); i++){
int clean_idx = -1;
for(int j=0; j<num_item; j++){
if(storage[i] == clean_storage[j]){
clean_idx = j;
break;
}
}
if(clean_idx == -1){
clean_storage[num_item] = storage[i];
clean_num[num_item] = num[i];
num_item += 1;
}
else{
clean_num[clean_idx] += num[i];
}
}
// 아래 코드에는 틀린 부분이 없습니다.
int num_max = -1;
string answer = "";
for(int i=0; i<num_item; i++){
if(clean_num[i] > num_max){
num_max = clean_num[i];
answer = clean_storage[i];
}
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] PCCE 기출문제 7번 (0) | 2024.02.09 |
---|---|
[프로그래머스] PCCE 기출문제 6번 (0) | 2024.02.09 |
[프로그래머스] PCCE 기출문제 5번 (0) | 2024.02.09 |
[프로그래머스] PCCE 기출문제 4번 (0) | 2024.02.09 |
[프로그래머스] PCCE 기출문제 3번 (0) | 2024.02.09 |