프로그래머스 - 최댓값과 최솟값

well-life-gm·2021년 12월 22일
0

프로그래머스

목록 보기
107/125

프로그래머스 - 최댓값과 최솟값

드디어 프로그래머스 레벨 2를 다 풀었다.

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string solution(string s) {
    string answer = "";
    string tmp = "";
    vector<int> nums;
    for(auto it : s) {
        if(isspace(it)) {
            nums.push_back(stoi(tmp));
            tmp.clear();
            continue;
        }
        tmp.push_back(it);
    }
    nums.push_back(stoi(tmp));

    sort(nums.begin(), nums.end());
    
    answer += to_string(nums[0]) + " " + to_string(nums[nums.size() - 1]);
    return answer;
}
profile
내가 보려고 만든 블로그

0개의 댓글