콘솔창 & 윈도우창/코딩 테스트

프로그래머스 lv2 최댓값과 최솟값 c++

게임 개발 2023. 10. 24. 13:08
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string solution(string s) {
    string answer = "";
    string Stemp = "";
    vector<int> V;

    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != ' ')
            Stemp += s[i];
        else 
        {
            V.push_back(stoi(Stemp));
            Stemp.clear();
        }


    }
    V.push_back(stoi(Stemp));

    sort(V.begin(), V.end());
    
    answer += to_string(V.front()) + " " + to_string(V.back());


    return answer;
}

int main()
{
    string s = "1 2 3 4";

    cout << solution(s);

	return 0;
}

'콘솔창 & 윈도우창 > 코딩 테스트' 카테고리의 다른 글

Anagram문제  (0) 2024.04.11
백준 - 괄호 9012  (0) 2024.01.29
프로그래머스 lv1 덧칠하기  (0) 2023.11.17
블랙잭 게임 구현  (0) 2023.01.13
백준 A : 특식 배부 C언어  (0) 2023.01.08