문제풀이: ** 잘풀었다 생각
문자열로 바꿔준후 이어붙이고 다시 형변환하여 크기비교하기
#include <string>
#include <algorithm> // max 함수를 사용하기 위한 헤더
using namespace std;
int solution(int a, int b) {
// 두 숫자를 문자열로 변환하여 이어붙인 값 중 더 큰 값을 반환
string a_str = to_string(a);
string b_str = to_string(b);
int ab = stoi(a_str + b_str); // a를 앞에, b를 뒤에 붙인 값
int ba = stoi(b_str + a_str); // b를 앞에, a를 뒤에 붙인 값
return max(ab, ba);
}
'코딩테스트' 카테고리의 다른 글
프로그래머스_1단계_ 직사각형 별찍기C++ (0) | 2024.04.09 |
---|---|
프로그래머스_1단계_ 자릿수 더하기C++ (0) | 2024.04.09 |
프로그래머스_0단계_ A 강조하기C++ (0) | 2024.04.09 |
프로그래머스_0단계_ 공배수 C++ (0) | 2024.04.09 |
프로그래머스_0단계_n 번째 원소부터 C++ (0) | 2024.04.09 |