题解 | #a+b#
a+b
https://www.nowcoder.com/practice/4c39c984ea3848b48e111b8e71ec1dd4
#include<iostream> #include<string> using namespace std; void fuc(string s){ int i = 0; while(s.at(i)!=' ')i++; char num1[10001]; char num2[10001]; char num3[10001]; for(int j = 0;j<10001;j++){ num1[j] = '0'; num2[j] = '0'; num3[j] = '0'; } for(int j = 0;j<i;j++){ num1[i-1-j] = s.at(j); } for(int j = s.length()-1;j>i;j--){ num2[s.length()-1-j] = s.at(j); } int overflow = 0; for(int j = 0;j <10001;j++){ int count = num1[j]-'0'+num2[j]-'0'+overflow; if(count>=10){ overflow = 1; count = count - 10; } else overflow = 0; num3[j] = count+'0'; } //转置输出 int k = 10000; while(num3[k]=='0'){ // cout<<k<<' '; k--; } // cout<<"k is "<<k<<endl; while(k>=0){ cout<<num3[k]; k--; } } int main(){ char buffer[10000]; while(cin.getline(buffer,10000)){ if(cin.eof())break; string s = buffer; fuc(s); } return 0; }