내공얌냠 2022. 9. 16. 11:23

https://school.programmers.co.kr/learn/courses/30/lessons/12939

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

알게된 것

stringstream 을 사용해서 while(ss >> temp) 로 하나씩 뽑을 수 있다는 것.

내 코드

#include <string>
#include <vector>
#include <sstream>
#include <iostream>

using namespace std;

string solution(string s) {
    string answer = "";

    long long max = -10000000; long long min = 10000000;
    long long temp;
    stringstream ss(s);
    while(ss >> temp) {
        if (temp > max) max = temp;
        if (temp < min) min = temp;
    }

    answer = to_string(min) + " " + to_string(max);

    return answer;
}

친구의 리뷰

  • min, max 함수를 쓰자
  • 리턴을 바로 하자

 

728x90
반응형