156 条题解

  • -2
    @ 2023-8-31 23:04:01

    C++ 式普通写法

    #include<iostream>
    
    using namespace std;
    
    int a,b;
    
    int main(){
      cin >> a >> b;
      cout << a + b;
      return 0;
    }
    

    高精度

    #include<iostream>
    
    using namespace std;
    
    const int MAXN = 1e5 + 10;
    
    long long r;
    int c;
    char op;
    
    struct bigint{
      long long len,sz[MAXN] = {0};
    
      long long &operator [] (long long a){
        return sz[a];
      }
    
      void input(){
        string s;
        cin >> s;
        len = s.size();
        for (int i = 0; i < len; i++){
          sz[i] = s[len - i - 1] - '0';
        }
      }
    
      void output(){
        for (; len - 1 > 0 && !sz[len - 1]; len--){
        }
    
        for (int i = len - 1; i >= 0; i--){
          cout << sz[i];
        }
        cout << '\n';
      }
      bigint operator + (const bigint &b){
        bigint c;
        c.len = max(len,b.len) + 1;
        for (int i = 0; i < c.len; i++){
          c[i] = sz[i] + b.sz[i];
        }
    
        for (int i = 0; i < c.len - 1; i++){
          c[i + 1] += c[i] / 10,c[i] %= 10;
        }
        return c;
      }
    }a,b,ans;
    
    int main(){
      a.input(),b.input();
      ans = a + b;
      ans.output();
      return 0;
    }
    

    信息

    ID
    56
    时间
    1000ms
    内存
    1024MiB
    难度
    1
    标签
    递交数
    9332
    已通过
    4188
    上传者