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 |
不明WA...不过也不企望知道为什么了...姑且贴贴代码...#include <iostream> #include <string> using namespace std; int main() { string s,sum; int C; int count,len0,len1; sum = "0"; while (1) { cin >> s; if (s == "0") break; if (sum.length() <= s.length()) { string temp; temp = sum;sum = s;s = temp; sum.insert(0,"0"); } int len = s.length(); for (int j = 0;j < sum.length() - len;j++) s.insert(0,"0"); //每次输入加数以后,都会在加数前面补一个‘0’,用于最高位进位。 C = 0; for (int j = s.length() - 1;j >= 0;j--) { sum[j] += s[j] - '0' + C; if (sum[j] >= '0' + 10) { sum[j] -= 10; C = 1; } else C = 0; } } if (sum != "0") { int index = sum.find_first_not_of("0"); if (index != string::npos) sum = sum.substr(index); else sum = "0"; cout << sum << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator