서울에서 김서방 찾기

남태우·2020년 11월 28일
0

문제

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

추상화

반복문을 활용하여 찾기

코드

#include <iostream>
#include <string>
#include <vector>

using namespace std;

string solution(vector<string> seoul) {
    string answer = "";
    string loc;
    for(int i=0; i<seoul.size(); i++){
        if(seoul[i]=="Kim") {
            loc = to_string(i);
            answer.append("김서방은 "+loc+"에 있다");
        }
    }
    return answer;
}
profile
brand-new

0개의 댓글