zoukankan      html  css  js  c++  java
  • Luogu1601 A+B Problem (高精度加法)

    蒟蒻复习了下高精

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    
    #else
    
    #define D_e_Line ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 1007;
    
    char strA[N],strB[N];
    
    int a[N],b[N],c[N];
    
    inline void BigAdd(char *strA, char *strB){
    	int lenA = strlen(strA + 1), lenB = strlen(strB + 1);
    	R(i,1,lenA) a[lenA - i + 1] = strA[i]^'0';
    	R(i,1,lenB) b[lenB - i + 1] = strB[i]^'0';
    	int len = Max(lenA, lenB);
    	R(i,1,len){
    		c[i] += a[i] + b[i];
    		while(c[i] >= 10){
    			++c[i+1];
    			c[i] -= 10;
    		}
    	}
    	++len;
    	while(c[len] == 0 && len != 1) --len;
    	nR(i,len,1)
    		printf("%d", c[i]);
    }
    int main(){
    	scanf("%s%s", strA + 1, strB + 1);
    	BigAdd(strA, strB);
    	return 0;
    }
    

  • 相关阅读:
    codeforces 363B
    hdu 1075 字典树
    D
    C A Simple Job
    Washing Plates 贪心
    HDU 4143 A Simple Problem 分解因式
    ACdream 1236 Burning Bridges 割边 + 去重边
    E. Beautiful Subarrays 字典树
    反素数 -- 数学
    Codeforces Beta Round #79 (Div. 1 Only) B. Buses 树状数组
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11211429.html
Copyright © 2011-2022 走看看