×

# BUGCAL - Editorial

Author: Trung Nguyen
Tester: Oleksandr Kulkov
Editorialist: Oleksandr Kulkov

CAKEWALK

None

# PROBLEM:

You're given two numbers. Sum them up without carrying.

# QUICK EXPLANATION:

Just do what is written in statement.

# EXPLANATION:

One of possible codes to solve the problem:

    int a, b;
cin >> a >> b;
vector<int> A, B;
while(a) {
A.push_back(a % 10);
a /= 10;
}
while(b) {
B.push_back(b % 10);
b /= 10;
}
while(A.size() < B.size()) A.push_back(0);
while(B.size() < A.size()) B.push_back(0);
for(int i = 0; i < A.size(); i++) {
A[i] += B[i];
}
int ans = 0;
reverse(begin(A), end(A));
for(auto it: A) {
ans = ans * 10 + it % 10;
}
cout << ans << endl;


# AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.
Tester's solution can be found here.

# RELATED PROBLEMS:

4★melfice
811937
accept rate: 0%

6★meooow ♦
7.3k720

1

Love the quick explanation :P

(30 Oct '17, 14:06) 6★

Let me check by posting an answer if that option really works.

(30 Oct '17, 20:03)

 0 We can just find the actual sum and keep subtracting 10,100,1000... from it by looping the original numbers till the number with less number of digits gets exhausted(we subtract only if we get a carry from the previous place value). Here is the link to my solution:- My Solution answered 30 Oct '17, 14:22 2★ramini 61●5 accept rate: 8%
 0 Here is my approach to this problem :: https://www.codechef.com/viewsolution/17941473 answered 24 Mar '18, 03:45 318●1●10 accept rate: 1%
 0 Could not pass the subtask 2: #include #include #define ll long long int using namespace std; int main() { ll t; cin>>t; while(t--){ string a, b; cin>>a>>b; ll max_last = max(a.size(), b.size()); ll min_last = min(a.size(), b.size()); ll result[max_last]; ll i=max_last-1; for(ll j= min_last-1; j>=0; i--, j--){ ll sum = a[i]-'0' + b[j]-'0'; result[i] = sum ; } while(i>=0){ result[i] = a[i]-'0'; i--; } ll sum = 0; for(ll i=0; i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×1,688
×72
×64
×10

question asked: 24 Oct '17, 18:39

question was seen: 2,201 times

last updated: 22 Sep '18, 05:47