프로그래머스코딩테스트연습풀이/C언어

[프로그래머스/C언어] 더 크게 합치기

코코쵸마 2023. 7. 22. 18:11

문제
연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다.
12 ⊕ 3 = 123
3 ⊕ 12 = 312
양의 정수 a와 b가 주어졌을 때, a ⊕ b와 b ⊕ a 중 더 큰 값을 return 하는 solution 함수를 완성해 주세요.
단, a ⊕ b와 b ⊕ a가 같다면 a ⊕ b를 return 합니다.

솔루션

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int a, int b) {
    int answer = 0;
    int a_size = 1;
    int b_size = 1;
    int a_store = a;
    int b_store = b;
    while(1){
        a_size*=10;
        a /= 10;
        if(a == 0)
            break;
    }
    while(1){
        b_size*=10;
        b /= 10;
        if(b == 0)
            break;
    }
    if(a_store*b_size+b_store >= b_store*a_size+a_store)
        answer = a_store*b_size+b_store;
    else
        answer = b_store*a_size+a_store;
    return answer;
}


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

프로그래머스

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

programmers.co.kr