새발블로그
[프로그래머스/C++] 두 수의 연산값 비교하기 본문
문제
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;
}
'Problem Solving > Programmers' 카테고리의 다른 글
| [프로그래머스/C++] 수 조작하기 1 (0) | 2024.03.06 |
|---|---|
| [프로그래머스/C++] 주사위 게임 2 (0) | 2024.03.05 |
| [프로그래머스/C++] 문자열 돌리기 (0) | 2024.03.04 |
| [프로그래머스/C++] 대소문자 바꿔서 출력하기 (0) | 2024.03.04 |
| [프로그래머스/C++] 더 크게 합치기 (0) | 2024.03.04 |