문제

- string 을 0부터 마지막 자리까지 탐색하는 반복문 작성
- 각 숫자는 공백으로 구분되어 있으므로,
- 공백 나오기 전 까지
- 공백 나오면
- tmp 을 vector 에 추가
- tmp 초기화
- vetor 정렬
- 맨 앞에 값, 맨 뒤에 값 출력
풀이
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string s) {
string answer = "";
vector<int> v ;
string tmp = "";
for(int i=0;i<s.size();i++){
if(s[i] == ' '){
v.push_back(stoi(tmp));
tmp = "";
}else{
tmp += s[i];
}
}
v.push_back(stoi(tmp));
sort(v.begin(), v.end());
answer = to_string(v.front()) + " " + to_string(v.back());
return answer;
}