https://www.acmicpc.net/problem/10757
10757번: 큰 수 A+B
첫째 줄에 A와 B가 주어진다. (0 < A,B < 1010000)
www.acmicpc.net
#include <iostream>
#include <cstring> //strlen
using namespace std;
const int M = 10000 + 5;
int res[M];
char c1[M], c2[M];
int idx;
int p;
int num1, num2;
int main() {
cin >> c1 >> c2;
int len1 = strlen(c1);
int len2 = strlen(c2);
while (len1 || len2 || p) {
if (len1) {
num1 = c1[(len1--) - 1] - '0';
}
if (len2) {
num2 = c2[(len2--) - 1] - '0';
}
res[idx++] = (num1 + num2 + p) % 10;
p = num1 + num2 + p > 9 ? 1 : 0;
num1 = num2 = 0;
}
for (int i = idx - 1; i >= 0; i--) {
cout << res[i];
}
}
'알고리즘 > Baekjoon Online Judge' 카테고리의 다른 글
[stable_sort]https://www.acmicpc.net/problem/10814 (0) | 2020.02.25 |
---|---|
[DP] https://www.acmicpc.net/problem/1463 (0) | 2020.02.25 |
분할 정복을 이용한 최대공약수 (0) | 2020.01.27 |
https://www.acmicpc.net/problem/3055 (0) | 2020.01.10 |
https://www.acmicpc.net/problem/4963 (0) | 2020.01.02 |