去年刚学acm时写了一道大数A+B,现在无聊回头看看发现当时写的太屎太长,所以顺便写个精简点的:
#include#include using namespace std;string s1, s2;int main(){ while(cin >> s1 >> s2){ int j = 0; if(s1.size() < s2.size()) swap(s1, s2); int len1 = s1.size()-1; for(int i = s2.size()-1;i >= 0;i --) s1[len1--] += s2[i]-48; for(int i = s1.size()-1;i > 0;i --) s2[j++] = (s1[i]-48) % 10, s1[i-1] += (s1[i]-48)/10; if(s1[0] <= '9') s2[j] = s1[0]-48; else s2[j++] = (s1[0]-48)%10, s2[j] = (s1[0]-48)/10; for(int i = j;i >= 0;i--) printf("%d", s2[i]); printf("\n"); } return 0;}