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(문자) 문자가 공백인지 확인해주는 함수
'코딩테스트 연습' 카테고리의 다른 글
코딩테스트 - 이상한 문자 만들기 (0) | 2020.01.14 |
---|---|
코딩테스트 - 비밀지도(카카오 공채 1차) (0) | 2020.01.14 |
코딩테스트 - 약수의 합 (0) | 2020.01.14 |
코딩 테스트 - 시저 암호 (0) | 2020.01.13 |
코딩 테스트 - 문자열을 정수로 바꾸기 (0) | 2020.01.13 |