728x90
반응형
문제: https://school.programmers.co.kr/learn/courses/30/lessons/12939
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <string>
#include <vector>
using namespace std;
string solution(string s) {
s.push_back(' ');
bool Minus = false;
int Min = 987654321, Max = -987654321;
string str = "";
for (const auto& i : s)
{
if (i == 32)
{
if (Minus)
{
Min = min(Min, (stoi(str) * -1));
Max = max(Max, (stoi(str) * -1));
}
else
{
Min = min(Min, stoi(str));
Max = max(Max, stoi(str));
}
Minus = false;
str = "";
continue;
}
if (i == '-') Minus = true;
else str += i;
}
return to_string(Min) + " " + to_string(Max);
}
728x90
반응형
'📕알고리즘 문제 > 📝Programmers' 카테고리의 다른 글
[프로그래머스] Level 2 : 프로세스 (0) | 2024.11.20 |
---|---|
[프로그래머스] Level 3 : 디스크 컨트롤러 (0) | 2024.11.18 |
[프로그래머스] Level 3 : 거스름돈 (0) | 2024.09.20 |
[프로그래머스] Level 2 : 카카오프렌즈 컬러링북 (0) | 2024.09.13 |
[프로그래머스] Level 2 : 요격 시스템 (0) | 2024.09.11 |