안녕 세상아,

[c++/프로그래머스] LV2 최댓값과 최솟값 본문

프로그래머스

[c++/프로그래머스] LV2 최댓값과 최솟값

돈 많은 백수가 되고싶다 2023. 5. 5. 21:51

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);
}

프로그래머스는 레벨이 별로 안나눠져있어서 같은 레벨이어도 수준 차이가 천차만별 ㅎ

이건 굉장히 쉬운편이었다.