프로그래머스코딩테스트연습풀이/C++
[프로그래머스/C++] 더 크게 합치기
코코쵸마
2025. 2. 21. 19:36
문제
연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다.
12 ⊕ 3 = 123
3 ⊕ 12 = 312
양의 정수 a와 b가 주어졌을 때, a ⊕ b와 b ⊕ a 중 더 큰 값을 return 하는 solution 함수를 완성해 주세요.
단, a ⊕ b와 b ⊕ a가 같다면 a ⊕ b를 return 합니다.
솔루션
#include <string>
#include <vector>
using namespace std;
int solution(int a, int b) {
if(stoi(to_string(a)+to_string(b)) > stoi(to_string(b)+to_string(a))){
return stoi(to_string(a)+to_string(b));
}
else{
return stoi(to_string(b)+to_string(a));
}
}
https://school.programmers.co.kr/learn/courses/30/lessons/181939
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr