풀이
stringstream 사용하여 공백 기준으로 문자열 분리
분리한 문자열을 stoi로 int형변환하여 vector v에 push_back
sort 로 v 벡터 오름차순 정렬
최소값 : v의 처음 값 = v[0]
최대값 : v의 마지막 값 = v[v.size()-1]
answer에 삽입
string solution(string s) {
string answer = "";
vector<int> v;
string temp;
stringstream sstream;
sstream.str(s);
while (sstream >> temp) {
v.push_back(stoi(temp));
}
sort(v.begin(), v.end());
answer += to_string(v[0]);
answer += " ";
answer += to_string(v[v.size() - 1]);
return answer;
}
'코딩테스트 > 문제풀이' 카테고리의 다른 글
[프로그래머스] 프린터 C++ (0) | 2022.08.10 |
---|---|
[프로그래머스] 기능개발 C++ (0) | 2022.08.10 |
[프로그래머스] 최소공배수 C++ (0) | 2022.06.01 |
[프로그래머스] 주차 요금 계산 C++ (0) | 2022.05.12 |
[프로그래머스] k진수에서 소수 개수 구하기 C++ (0) | 2022.05.11 |