N

(프로그래머스 c++) [PCCE 기출문제] 5번 / 심폐소생술 본문

프로그래머스 알고리즘/0 & 1단계

(프로그래머스 c++) [PCCE 기출문제] 5번 / 심폐소생술

naeunchan 2025. 7. 26. 15:20
728x90
반응형
 

https://school.programmers.co.kr/learn/courses/30/lessons/340203

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

주어진 cpr과 basic_order를 순회하면서 같은 값이면 해당 인덱스 값을 +1 해서 answer에 있는 값을 바꿔주는 문제.

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<string> cpr) {
    vector<int> answer = {0, 0, 0, 0, 0};
    vector<string> basic_order = {"check", "call", "pressure", "respiration", "repeat"};

    for(int i=0; i< cpr.size(); i++){ // 빈칸
        for(int j=0; j< basic_order.size(); j++){ // 빈칸
            if(cpr[i] == basic_order[j]){
                answer[i] = j + 1; // 빈칸
                break;
            }
        }
    }

    return answer;
}
728x90
반응형