-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP10035.cpp
More file actions
37 lines (34 loc) · 725 Bytes
/
P10035.cpp
File metadata and controls
37 lines (34 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <stdio.h>
/*
Count carries
*/
int main() {
while(true) {
// Read input and check stop condition:
unsigned long a, b;
std::cin >> a >> b;
if(a == 0 && b == 0)
return 0;
// Compute output:
int carries = 0;
bool lastCarry = false;
while(a > 0 || b > 0) {
int ra = a%10;
int rb = b%10;
bool carry = lastCarry ? ra+rb >= 9 : ra+rb >= 10;
if(carry)
++carries;
lastCarry = carry;
a/=10;
b/=10;
}
// Pretty print output:
if(carries == 0)
printf("No carry operation.\n");
else if(carries == 1)
printf("1 carry operation.\n");
else
printf("%i carry operations.\n", carries);
}
}