문제 : 최댓값과 최솟값
풀이 방법
if else 문으로 숫자일 경우를 배열에 넣고 최댓값과 최솟값만 구해주면 된다
소스 코드
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string s) {
string answer = "";
vector<int> arr;
string temp;
for(char & c : s) {
if(c == '-' || c != ' ') {
temp.push_back(c);
}
else if (c == ' ') {
arr.push_back(stoi(temp));
temp.clear();
}
}
arr.push_back(stoi(temp));
answer.append(to_string(*min_element(arr.begin(), arr.end())));
answer.push_back(' ');
answer.append(to_string(*max_element(arr.begin(), arr.end())));
return answer;
}
'정리 전 게시글 > 공부 관련' 카테고리의 다른 글
[프로그래머스 Level 1, Java] 정수 제곱근 판별 (0) | 2022.08.04 |
---|---|
[안드로이드, Java] 리사이클뷰 아이템 마진 적용하기, RecyclerView Item Margin (0) | 2022.08.03 |
[안드로이드, Java] View 동적으로 addView() 하고 마진 적용 하는 방법 (0) | 2022.08.02 |
[프로그래머스 Level 2, C++] 가장 큰 수 (0) | 2022.07.29 |
startActivity(intent); 팅김 오류 해결법 (0) | 2022.07.28 |