본문 바로가기
c++/프로그래머스

[프로그래머스] 더 크게 합치기(c++)

by ilp 2023. 12. 26.
반응형

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

 

프로그래머스

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

programmers.co.kr



#include <bits/stdc++.h>
using namespace std;

int solution(int a, int b) {
    int ans1=0,ans2=0;
    
    string a1=to_string(a);
    string b1=to_string(b);
    
    return max(stoi(a1+b1),stoi(b1+a1));
}

 

ans1과 ans2를 만들었지만 사용하지 않았다.

입력된 정수a,b를 문자열로 바꾸어 준다. (to_string(_)사용)

그리고 그 문자열을 더해주고 다시 숫자로 바꾸어준다.(stoi(_)사용)

그리고 그 둘의 max값을 출력했다.


 
반응형