[C++] 프로그래머스 문자열로 변환

문제설명

정수 n이 주어질 때, n을 문자열로 변환하여
return하도록 solution 함수를 완성해주세요.


제한사항

• 1 ≤ n ≤ 10000


입출력 예

n result
123 “123”
2573 “2573”


풀이

정수 n을 문자열로 변환하는 간단한 구현 문제입니다.

#include <string>
#include <vector>

using namespace std;

string solution(int n) {
    string answer = "";
    
    answer = to_string(n);
    
    return answer;
}


결과

코드 실행결과

Categories:

Updated:

Leave a comment