코딩테스트/프로그래머스

[2] 최댓값과 최솟값

ShovelingLife 2023. 7. 23. 19:45
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

string solution(string s)
{
	vector<int> v;
	string temp = "";

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == ' ')
		{
			v.push_back(stoi(temp));
			temp = "";
		}
		else
			temp += s[i];
	}
	v.push_back(stoi(temp));
	sort(v.begin(), v.end());
	return to_string(v.front()) + ' ' + to_string(v.back());
}