UVa Problem Solution: 10035 - Primary Arithmatic


Simple problem. Just count it.

Code:
  1. /*************************************************************************
  2.  * Copyright (C) 2008 by liukaipeng                                      *
  3.  * liukaipeng at gmail dot com                                           *
  4.  *************************************************************************/
  5. /* @JUDGE_ID 00000 10035 C++ "Primary Arithmatic" */
  6. #include <algorithm>
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <deque>
  10. #include <fstream>
  11. #include <iostream>
  12. #include <list>
  13. #include <map>
  14. #include <queue>
  15. #include <set>
  16. #include <stack>
  17. #include <string>
  18. #include <vector>
  19. using namespace std;
  20.            
  21. int main(int argc, char *argv[])
  22. {
  23. #ifndef ONLINE_JUDGE
  24.   freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
  25.   freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
  26. #endif
  27.   char const *msgs[] = {
  28.     "No carry operation.",
  29.     "1 carry operation.",
  30.     "2 carry operations.",
  31.     "3 carry operations.",
  32.     "4 carry operations.",
  33.     "5 carry operations.",
  34.     "6 carry operations.",
  35.     "7 carry operations.",
  36.     "8 carry operations.",
  37.     "9 carry operations.",
  38.   };
  39.   int a, b;
  40.   while (scanf("%d %d/n", &a, &b) && !(a == 0 && b == 0)) {
  41.     int ncarries = 0;
  42.     for (int carry = 0; !(a == 0 && b == 0); a /= 10, b /= 10) {
  43.       carry = (a % 10 + b % 10 + carry) / 10;
  44.       ncarries += carry;
  45.     }
  46.     puts(msgs[ncarries]);
  47.   }
  48.   return 0;
  49. }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章