标签:amp char return c++ span ret rev cout class
#include <bits/stdc++.h> using namespace std; int main() { string a,b,c; cin>>c>>a>>b; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); reverse(c.begin(),c.end()); string s; int up=0,sum,k; while(a.length()!=b.length()) { if(a.length()>b.length()) b += ‘0‘; else a += ‘0‘; } for(int i=0;i<a.length();i++) { sum = a[i]-‘0‘+b[i]-‘0‘+up; if(i>c.length()-1 || c[i]==‘0‘) k=10; else k=c[i]-‘0‘; up = sum/k; sum %= k; s = (char)(sum + ‘0‘) + s; } if(up > 0) s = (char)(up + ‘0‘) + s; int count = 0; while(s[count] == ‘0‘ && s.length() > 1) s.erase(count, 1); cout<<s<<endl; return 0; }
标签:amp char return c++ span ret rev cout class
原文地址:https://www.cnblogs.com/tonyyy/p/10495007.html