Krononberg

프로그래머스) 최댓값과 최솟값 c++ 본문

개발 로그/알고리즘

프로그래머스) 최댓값과 최솟값 c++

k._. 2021. 9. 13. 08:59

point : string <-> integer 변환 할 수 있는지

 

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

using namespace std;

string solution(string s) {
    string tmp = "";
    vector<int>v;
    for(int i =0; i < s.size(); i++){
        if(s[i]!=' ') tmp += s[i];
        else if (s[i] == ' ') {
            v.push_back(stoi(tmp));
            tmp = "";
        }
        if(i == s.size()-1)
            v.push_back(stoi(tmp));
    }
    sort(v.begin(),v.end());
    string x = to_string(v[0]) + " " + to_string(v[v.size()-1]);

    return x;
}