https://programmers.co.kr/learn/courses/30/lessons/12939
#include <string>
#include <vector>
using namespace std;
vector<string> strtok(string str, char delim = ' '){ // strtok
vector<string> ret;
int prev=0;
for(int i=0;i<str.size();i++){
if(str[i]==delim){
ret.push_back(str.substr(prev,i-prev));
prev=i+1;
}
}
if(str.size()!=prev)
ret.push_back(str.substr(prev,str.size()-prev));
return ret;
}
string solution(string s) {
string answer = "";
vector<string> num = strtok(s);
int mini = stoi(num[0]);
int maxi = stoi(num[0]);
for(int i=0;i<num.size();i++){
mini = min(mini,stoi(num[i]));
maxi = max(maxi,stoi(num[i]));
}
answer = to_string(mini) +" "+ to_string(maxi);
return answer;
}
#include <string>
#include <vector>
using namespace std;
string solution(string s) {
string answer = "";
string szTemp;
pair<int, int> nMinMax{ 999999, -999999 };
while (true)
{
int pos = s.find(" ");
szTemp = s.substr(0, pos);
s = s.substr(pos + 1);
nMinMax.first = min(nMinMax.first, stoi(szTemp));
nMinMax.second = max(nMinMax.second, stoi(szTemp));
if (pos == s.npos)
break;
}
answer += to_string(nMinMax.first) + string(" ") + to_string(nMinMax.second);
return answer;
}