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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
   | // //  main.cpp //  largeNumberSort // //  Created by Richard on 9/9/15. //  Copyright (c) 2015 luxin. All rights reserved. //
 
  #include <string> #include <iostream>
  #define MAX_NUM 2000 using namespace std;
  int add1[MAX_NUM],add2[MAX_NUM],res[MAX_NUM],tmp; char tmp1[MAX_NUM],tmp2[MAX_NUM]; int N;
  int main() {     cin>>N;     int  count = 0;     tmp = 0;     while (count < N) {                  memset(add1,0,sizeof(add1));         memset(add2,0,sizeof(add2));         memset(res,0,sizeof(res));         memset(tmp1,0,sizeof(tmp1));         memset(tmp2,0,sizeof(tmp2));                  cin>>tmp1>>tmp2;                  int len1 = static_cast<int>(strlen(tmp1));         int len2 = static_cast<int>(strlen(tmp2));                  for (int i = len1-1,k = 0; i >= 0; --i,++k) {             add1[k] = tmp1[i] - '0';                      }                  for (int i = len2-1,k = 0; i >= 0; --i,++k) {             add2[k] = tmp2[i] - '0';                  }                  if (len1 >= len2) {             for (int i = 0; i <= len1; ++i) {                 res[i] = (add1[i] + add2[i] + tmp) % 10;                 tmp = (add1[i] + add2[i] + tmp) / 10;             }                      }else if (len1 < len2) {             for (int i = 0; i <= len2; ++i) {                 res[i] = (add1[i] + add2[i] + tmp) % 10;                 tmp = (add1[i] + add2[i] + tmp) / 10;             }         }                  int len = 0;         if (len1 >= len2) len = len1;         else len = len2;         //TODO: priint it         cout<<"Case "<<(count+1)<<":\n"<<tmp1<<" + "<<tmp2<<" = ";         if (res[len] != 0) cout<<res[len];         for (int i = len-1; i >= 0; --i) {             cout<<res[i];         }         cout<<"\n";         if (count != N-1) {             cout<<"\n";         }         count++;     }      }
 
   |