프로그래머스코딩테스트연습풀이/C언어
[프로그래머스/C언어] 두 수의 연산값 비교하기
코코쵸마
2023. 7. 31. 15:01
문제
연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다.
12 ⊕ 3 = 123
3 ⊕ 12 = 312
양의 정수 a와 b가 주어졌을 때, a ⊕ b와 2 * a * b 중 더 큰 값을 return하는 solution 함수를 완성해 주세요.
단, a ⊕ b와 2 * a * b가 같으면 a ⊕ b를 return 합니다.
솔루션
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
int solution(int a, int b) {
int answer = 0;
char str1[11];
char str2[11];
sprintf(str1, "%d", a);
sprintf(str2, "%d", b);
strcat(str1, str2);
answer = atoi(str1);
answer = (answer < 2 * a * b)? 2 * a * b: answer;
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/181938
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr