728x90
반응형

🔗 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/12939
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
👩💻 코드
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
string solution(string s) {
vector<int> numbers;
stringstream ss(s);
string digit;
while (ss >> digit) {
numbers.push_back(stoi(digit));
}
return to_string(*min_element(numbers.begin(), numbers.end())) + " " + to_string(*max_element(numbers.begin(), numbers.end()));
}
📝 풀이
stringstream을 이용하여 공백으로 구분된 숫자들을 추출하여 numbers 벡터에 저장한다.
numbers 벡터에서 최솟값과 최댓값을 찾아 정답 형식으로 문자열을 생성하여 return 한다.
728x90
반응형
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 최솟값 만들기 (0) | 2024.07.11 |
---|---|
[프로그래머스] 올바른 괄호 (0) | 2024.07.10 |
[프로그래머스] 가장 많이 받은 선물 (0) | 2024.07.09 |
[프로그래머스] [PCCP 기출문제] 1번 / 붕대 감기 (0) | 2024.07.09 |
[프로그래머스] 신고 결과 받기 (0) | 2024.07.06 |