Skip to content

Commit

Permalink
Problem 10035
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanStarkey committed Apr 17, 2013
1 parent 069c2f1 commit b361b11
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
59 changes: 59 additions & 0 deletions uva10035.cpp
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;
}
4 changes: 4 additions & 0 deletions uva10035.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
123 456
555 555
123 594
0 0

0 comments on commit b361b11

Please sign in to comment.