Simple problem. Just count it.
Code:
- /*************************************************************************
- * Copyright (C) 2008 by liukaipeng *
- * liukaipeng at gmail dot com *
- *************************************************************************/
- /* @JUDGE_ID 00000 10035 C++ "Primary Arithmatic" */
- #include <algorithm>
- #include <cstdio>
- #include <cstring>
- #include <deque>
- #include <fstream>
- #include <iostream>
- #include <list>
- #include <map>
- #include <queue>
- #include <set>
- #include <stack>
- #include <string>
- #include <vector>
- using namespace std;
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
- freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
- #endif
- char const *msgs[] = {
- "No carry operation.",
- "1 carry operation.",
- "2 carry operations.",
- "3 carry operations.",
- "4 carry operations.",
- "5 carry operations.",
- "6 carry operations.",
- "7 carry operations.",
- "8 carry operations.",
- "9 carry operations.",
- };
- int a, b;
- while (scanf("%d %d/n", &a, &b) && !(a == 0 && b == 0)) {
- int ncarries = 0;
- for (int carry = 0; !(a == 0 && b == 0); a /= 10, b /= 10) {
- carry = (a % 10 + b % 10 + carry) / 10;
- ncarries += carry;
- }
- puts(msgs[ncarries]);
- }
- return 0;
- }