zoukankan      html  css  js  c++  java
  • 【POJ】1503

    Code

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    const int N = 128;
    
    struct bigInt{
        int num[N];     // num[0]存长度,倒序不压位
        void plus(const bigInt &x){
            int len = max(num[0], x.num[0]);
            num[0] = len;
            for (int i = 1; i <= len; ++i){
                num[i] += x.num[i];
                if(num[i] >= 10){
                    num[i]-=10;
                    num[i + 1]++;
                }
            }
            if(num[len + 1])num[0] = len + 1;
        }
        inline void read(){
            memset(num, 0, sizeof(num));
            char ch = getchar();
            while('0' <= ch && ch <= '9'){
                num[0]++;
                num[num[0]] = ch - 48;
                ch = getchar();
            }
            for(int i = 1; i <= num[0] / 2; ++i)swap(num[i], num[num[0] - i + 1]);
        }
        inline void writeln(){
            for(int i = num[0]; i >= 1; --i)printf("%d", num[i]);
            printf("
    ");
        }
        inline bool zeroQ(){
            if(num[0] == 1 && num[1] == 0)return true;
            return false;
        }
    };
    
    int main(int argc, char const *argv[]){
        bigInt a, b;
        a.read();
        b.read();
        while(!b.zeroQ()){
            a.plus(b);
            b.read();
        }
        a.writeln();
        return 0;
    }
    

    Review

    • 高精度水题,随便写写
  • 相关阅读:
    ES6新语法之---块作用域let/const(2)
    sass变量
    Ruby(或cmd中)输入命令行编译sass
    sass的安装
    鼠标滚动兼容
    HTML5新标签兼容——> <!--<if lt IE 9><!endif-->
    #include stdio.h(7)
    #include stdio.h(6)
    #include stdio.h(5)
    #include stdio.h(3)
  • 原文地址:https://www.cnblogs.com/mojibake/p/15307335.html
Copyright © 2011-2022 走看看