프로그래머스(Programmers)

Level 1> 서울에서 김서방 찾기

cepiloth 2018. 8. 8. 16:29
반응형

https://programmers.co.kr/learn/courses/30/lessons/12919


1. 문제


2. 알고리즘

키워드 - 구현, 문자열


3. 코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string>
#include <vector>
 
using namespace std;
 
string solution(vector<string> seoul) {
    string answer = "";
    
    const int size = seoul.size();
    
    int cand = 0;
    for(int i=0; i<size; i++) {
        if(seoul[i] == "Kim") {
            cand = i;
            break;
        }
    }
    
    answer += "김서방은 ";
    answer += to_string(cand);
    answer += "에 있다";
    return answer;
}
cs

반응형