프로그래머스 레벨 2 테스트

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
string solution(string s) 
{
    string answer = "";
    vector<int> vecAnswer;
 
    string str = "";
    for (int i = 0; i < s.size(); i++)
    {
 
        if (!isspace(s[i]))
            str += s[i];
 
        if (isspace(s[i]))
        {
            int iCheck = stoi(str);
            vecAnswer.emplace_back(iCheck);
 
            str = "";
        }
 
        if (i == s.size() - 1)
        {
            int iCheck = stoi(str);
            vecAnswer.emplace_back(iCheck);
        }
 
    }
 
    sort(vecAnswer.begin(), vecAnswer.end());
 
    answer += to_string(vecAnswer.front());
    answer += " ";
    answer += to_string(vecAnswer.back());
 
    return answer;
}
 

isspace(문자) 문자가 공백인지 확인해주는 함수

 

+ Recent posts