코딩테스트/프로그래머스
[Level 1][C++] 서울에서 김서방 찾기
MJ.Lee
2024. 9. 27. 22:48
#include <string>
#include <vector>
using namespace std;
string solution(vector<string> seoul) {
int idx;
for(int i=0; i<seoul.size(); i++)
{ if(seoul[i].compare("Kim")==0) //두 string비교. 같으면 0, 사전 편찬순 앞이면 양수, 뒤면 음수 반환.
{
idx =i;
break;
}
}
string answer = "김서방은 "+to_string(idx)+"에 있다";
return answer;
}