TIL_6주차(4) 코드카타: 알고리즘

원진·2025년 1월 23일

알고리즘

1. 서울에서 김서방 찾기

풀이:

#include <string>
#include <vector>

using namespace std;

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

서울에서 김서방 찾기

0개의 댓글