๋ฌธ์
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ์์ธ์์ ๊น์๋ฐฉ ์ฐพ๊ธฐ
Stringํ ๋ฐฐ์ด seoul์ element์ค "Kim"์ ์์น x๋ฅผ ์ฐพ์, "๊น์๋ฐฉ์ x์ ์๋ค"๋ String์ ๋ฐํํ๋ ํจ์, solution์ ์์ฑํ์ธ์. seoul์ "Kim"์ ์ค์ง ํ ๋ฒ๋ง ๋ํ๋๋ฉฐ ์๋ชป๋ ๊ฐ์ด ์ ๋ ฅ๋๋ ๊ฒฝ์ฐ๋ ์์ต๋
programmers.co.kr
์ฝ๋
#include <string>
#include <vector>
using namespace std;
string solution(vector<string> seoul) {
string answer= "";
answer = "๊น์๋ฐฉ์ ";
for(int i=0; i<seoul.size(); i++){
if(seoul[i]=="kim"){
answer+= to_string(i);
break;
}
answer+="์ ์๋ค";
return answer;
}
๋๊ธ