Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
终于过了,999+9是个好测试用例#include <iostream> #include <string> using namespace std; const int MAX = 103; string a,b,result; void ltrim(string& str) { string::size_type pos1 = str.find_first_not_of('0'); str = str.substr(pos1 == string::npos ? 0 : pos1, str.length() - 1); } void expand(string& str) { int i=str.length(); while(i++<MAX){ str = "0" + str; } } int main(){ int isover = 0; cin >> result; while(cin >> a){ if(a == "0") break; int l1,l2; l1 = a.length(); l2 = result.length(); expand(result); expand(a); int l = (l1>l2)?l1:l2; int r=0; for(int i=0;i<l||isover;i++){ r = (a[MAX-i-1]-'0')+ (result[MAX-i-1]-'0') + isover; int rest = r%10; result[MAX-i-1] = rest + '0'; isover = r/10; } } ltrim(result); cout << result << endl; return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator