새발블로그

[프로그래머스/C++] 두 수의 연산값 비교하기 본문

Problem Solving/Programmers

[프로그래머스/C++] 두 수의 연산값 비교하기

EUG 2024. 3. 4. 16:17

문제

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

풀이방법

C++ algorithm 헤더를 적용해보았다.

 이 김에 STL 함수 정리...

1. SORT 함수

- quick sort -> O(nlgn)

- sort(start주소, end 주소) [start, end] start 포함, end 불포함

 

2. max 함수

- max(m, n) 

- 최대값 반환

 

3. min 함수

- min(m, n)

- 최솟값 반환

 

풀이

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(int a, int b) {
    int answer = 0;
    string numA = to_string(a);
    string numB = to_string(b);
    int maxValue = max(stoi(numA+numB), 2*stoi(numA)*stoi(numB));
    answer = maxValue;
    return answer;
}