문제 링크입니다 https://programmers.co.kr/learn/courses/30/lessons/12919
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
String형 배열 seoul의 element중 Kim의 위치 x를 찾아, 김서방은 x에 있다는 String을 반환하는 함수를 완성하는 문제였습니다. to_string 함수를 사용하여 문제를 해결했습니다.
[소스코드]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 += "김서방은 "; | |
answer += to_string(i); | |
answer += "에 있다"; | |
} | |
} | |
return answer; | |
} |

'알고리즘 > Programmers' 카테고리의 다른 글
프로그래머스 LEVEL 2 : 숫자의 표현 (0) | 2020.04.04 |
---|---|
프로그래머스 LEVEL 2 : 최댓값과 최솟값 (0) | 2020.04.01 |
프로그래머스 LEVEL 1 : 같은 숫자는 싫어 (0) | 2020.03.29 |
프로그래머스 LEVEL 2 : 최솟값 만들기 (0) | 2020.03.27 |
프로그래머스 LEVEL 2 : 짝지어 제거하기 (0) | 2020.03.25 |