Task: | ModAdd |
Sender: | djbb |
Submission time: | 2016-09-24 13:50:13 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.06 s | details |
#6 | ACCEPTED | 0.06 s | details |
#7 | ACCEPTED | 0.06 s | details |
#8 | ACCEPTED | 0.06 s | details |
#9 | ACCEPTED | 0.06 s | details |
#10 | ACCEPTED | 0.05 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:5:53: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] #define absint(a, b) ( ((a)> (b)) ? (a - b): (b - a)) ^ input/code.cpp:18:19: note: in expansion of macro 'absint' for(int i = 0; i<absint(num1.length(), num2.length()); i++){ ^ input/code.cpp:29:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i = 0; i<num1.length(); i++){ ^
Code
#include <algorithm> #include <iostream> #include <string> #define absint(a, b) ( ((a)> (b)) ? (a - b): (b - a)) #define min(a, b) ( a>b ? b : a) int main(){ using namespace std; ios::sync_with_stdio(0); string num1, num2, pad = ""; //read first number as string getline(cin, num1); getline(cin, num2); //make same length for(int i = 0; i<absint(num1.length(), num2.length()); i++){ pad += "0"; } if(num1.length() < num2.length()){ num1 = pad + num1; } else { num2 = pad + num2; } int op1, op2; //since there is no carry, we can sum from left side and print as we go for(int i = 0; i<num1.length(); i++){ op1 = num1[i] - '0'; op2 = num2[i] - '0'; num1[i] = ((op1 + op2) % 10) + 48; } num1.erase(0, min(num1.find_first_not_of('0'), num1.size()-1)); cout << num1 << "\n"; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3797629225 9766508989 |
correct output |
---|
2453127104 |
user output |
---|
2453127104 |
Test 2
Verdict: ACCEPTED
input |
---|
552139016901047883384892240490... |
correct output |
---|
552139016901047883384892240490... |
user output |
---|
552139016901047883384892240490... |
Test 3
Verdict: ACCEPTED
input |
---|
860793811134668093345482099582... |
correct output |
---|
487710306894083216377653715430... |
user output |
---|
487710306894083216377653715430... |
Test 4
Verdict: ACCEPTED
input |
---|
2 870841652294197226626825161089... |
correct output |
---|
870841652294197226626825161089... |
user output |
---|
870841652294197226626825161089... |
Test 5
Verdict: ACCEPTED
input |
---|
0 404905566051213252279994991040... |
correct output |
---|
404905566051213252279994991040... |
user output |
---|
404905566051213252279994991040... |
Test 6
Verdict: ACCEPTED
input |
---|
430112167406460960088878635088... |
correct output |
---|
430112167406460960088878635088... |
user output |
---|
430112167406460960088878635088... |
Test 7
Verdict: ACCEPTED
input |
---|
867016005819001635643395991596... |
correct output |
---|
999999999999999999999999999999... |
user output |
---|
999999999999999999999999999999... |
Test 8
Verdict: ACCEPTED
input |
---|
120453771521975552204976752778... |
correct output |
---|
0 |
user output |
---|
0 |
Test 9
Verdict: ACCEPTED
input |
---|
239979749009277805816504910098... |
correct output |
---|
239979749009277805816504910098... |
user output |
---|
239979749009277805816504910098... |
Test 10
Verdict: ACCEPTED
input |
---|
990963963634143754324162574923... |
correct output |
---|
818540385713473048971388312665... |
user output |
---|
818540385713473048971388312665... |