标签:
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string A, B; cin>>A>>B; vector<int> vecSum; int lenA = A.length(); int lenB = B.length(); int temp; int carry =0; int indexA = lenA -1 , indexB = lenB -1; while(indexA >= 0 && indexB >= 0) { temp = carry + (A[indexA] -'0') + (B[indexB] - '0'); vecSum.push_back(temp%10); carry = temp /10; indexA--; indexB--; } while(indexA >= 0) { temp = carry + (A[indexA] -'0'); vecSum.push_back(temp%10); carry = temp /10; indexA--; } while(indexB >= 0) { temp = carry + (B[indexB] - '0'); vecSum.push_back(temp%10); carry = temp /10; indexB--; } while(carry != 0) { vecSum.push_back(carry%10); carry /= 10; } for(vector<int>::reverse_iterator itr = vecSum.rbegin(); itr != vecSum.rend(); ++itr) { cout<<*itr; } cout<<endl; return 0; }
标签:
原文地址:http://blog.csdn.net/xiaohanstu/article/details/45603333