【Luogu1601】【模板】A+B Problem(高精)

problem

solution

codes

#include<iostream>
#include<algorithm>
#include<string>
#define maxn 1010
using namespace std;
int a[maxn],b[maxn],c[maxn];
int main(){
    string s1, s2;
    cin>>s1>>s2;
    a[0] = s1.size(); b[0] = s2.size();
    for(int i = 1; i <= a[0]; i++)a[i] = s1[a[0]-i]-'0';
    for(int i = 1; i <= b[0]; i++)b[i] = s2[b[0]-i]-'0';
    c[0] = max(a[0],b[0])+1;
    for(int i = 1; i <= c[0]; i++){
        c[i] += a[i]+b[i];
        if(c[i] >= 10){
            c[i] %= 10;
            c[i+1]++;
        }
    }
    while(c[0]>1 && c[c[0]]==0)c[0]--;
    for(int i = c[0]; i >= 1; i--)
        cout<<c[i];
    cout<<"\n";
    return 0;
}
posted @ 2018-06-08 22:01  gwj1139177410  阅读(117)  评论(0)    收藏  举报
选择