◈ 문제 설명
◈ 문제 설명 링크
코딩테스트 연습 - 두 수의 합 | 프로그래머스 스쿨 (programmers.co.kr)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
◈ 작성 코드
#include <string>
#include <vector>
#include <cmath>
using namespace std;
string solution(string a, string b)
{
int alen = a.length();
int blen = b.length();
int carry = 0;
string answer = "";
for(int i = 1; i <= max(alen, blen); i++)
{
int numa = (i > alen)? 0 : a[alen-i]-'0';
int numb = (i > blen)? 0 : b[blen-i]-'0';
int num = numa + numb + carry;
if(num >= 10)
{
carry = 1;
}
else
{
carry = 0;
}
char numc = num%10+'0';
answer = numc + answer;
}
if(carry)
{
answer = "1"+answer;
}
return answer;
}
'[프로그래머스 C++] > LEVEL 0' 카테고리의 다른 글
[프로그래머스 C++] 배열의 원소 삭제하기 (0) | 2024.01.29 |
---|---|
[프로그래머스 C++] 문자열로 변환 (0) | 2024.01.29 |
[프로그래머스 C++] 0 떼기 (0) | 2024.01.17 |
[프로그래머스 C++] 문자열을 정수로 변환하기 (0) | 2024.01.17 |
[프로그래머스 C++] 문자열 정수의 합 (0) | 2024.01.17 |