-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
069c2f1
commit b361b11
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* UVa Online Judge Judge - Problem 10035 | ||
*/ | ||
|
||
#include <iostream> | ||
#include <sstream> | ||
|
||
std::string output(unsigned carry) | ||
{ | ||
switch (carry) | ||
{ | ||
case 0: | ||
return "No carry operation."; | ||
case 1: | ||
return "1 carry operation."; | ||
default: | ||
std::stringstream ss; | ||
ss << carry << " carry operations."; | ||
return ss.str(); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
while (true) | ||
{ | ||
unsigned long one; | ||
unsigned long two; | ||
std::cin >> one; | ||
std::cin >> two; | ||
|
||
if ((one == 0) && (two == 0)) | ||
return 0; | ||
|
||
unsigned totalCarry = 0; | ||
unsigned carry = 0; | ||
do | ||
{ | ||
unsigned oneDigit = one%10; | ||
one = one/10; | ||
unsigned twoDigit = two%10; | ||
two = two/10; | ||
|
||
if ((oneDigit+twoDigit+carry) >= 10) | ||
{ | ||
totalCarry++; | ||
carry = 1; | ||
} | ||
else | ||
{ | ||
carry = 0; | ||
} | ||
|
||
} while (!((one == 0) && (two == 0))); | ||
|
||
std::cout << output(totalCarry) << std::endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
123 456 | ||
555 555 | ||
123 594 | ||
0 0 |