Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Set
- Sort
- 정렬
- 최소공배수
- 이분탐색
- 다이나믹프로그래밍
- 분할정복
- stoi
- BFS
- 백트래킹
- vector
- priority_queue
- 에라토스테네스의 체
- 그래프
- 프로그래머스
- int
- N과M
- DFS
- 백준
- 오블완
- 우선순위큐
- 알고리즘
- C++
- 배열
- 유클리드호제법
- 문자열
- map
- 티스토리챌린지
- 깊이우선탐색
- DP
Archives
- Today
- Total
안녕 세상아,
[c++/프로그래머스] LV2 최댓값과 최솟값 본문
https://school.programmers.co.kr/learn/courses/30/lessons/12939
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
using namespace std;
string solution(string s) {
string answer = "";
//나누어진 문자열에서 필요한 자료형 뽑아낼 때 사용
stringstream stream(s);
vector<int> v;
stream.str(s);
string word;
//입력값에서 하나씩 분리해서 vector에 삽입
while (stream>>word)
{
int num = stoi(word);
v.push_back(num);
}
sort(v.begin(), v.end());
string str = to_string(v[0]);
string str1 = to_string(v[v.size() - 1]);
answer = str +" "+ str1;
return answer;
}
//출력값 확인을 위해
int main() {
string s;
getline(cin, s);
cout << solution(s);
}
프로그래머스는 레벨이 별로 안나눠져있어서 같은 레벨이어도 수준 차이가 천차만별 ㅎ
이건 굉장히 쉬운편이었다.
'프로그래머스' 카테고리의 다른 글
[c++/프로그래머스] N개의 최소공배수 (0) | 2023.08.31 |
---|---|
[c++] 구명보트 (0) | 2023.08.17 |
[c++/프로그래머스] LV 2 카펫 (0) | 2023.06.27 |
[c++/프로그래머스] LV2 최솟값 만들기 (0) | 2023.05.08 |
[c++/프로그래머스] LV2 JadenCase 문자열 만들기 (0) | 2023.05.07 |