高精度模板

目录

高精度系列

倒存处理

 string A, B;
    cin >> A >> B;
    int len = max(A.length(), B.length());
    for (int i = A.length() - 1, j = 1; i >= 0; ++j, --i)
        ar[j] = A[i] - '0';
    for (int i = B.length() - 1, j = 1; i >= 0; ++j, --i)
        br[j] = B[i] - '0';

A+B

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define Maxlen 520
int ar[Maxlen], br[Maxlen], cr[Maxlen];
int main()
{
    string A, B;
    cin >> A >> B;
    int len = max(A.length(), B.length());
    for (int i = A.length() - 1, j = 1; i >= 0; ++j, --i)
        ar[j] = A[i] - '0';
    for (int i = B.length() - 1, j = 1; i >= 0; ++j, --i)
        br[j] = B[i] - '0';

    for (int i = 1; i <= len; ++i)
    {
        cr[i] += ar[i] + br[i];
        if (cr[i] > 9)
            cr[i + 1]++;
        cr[i] %= 10;
    }
    if (cr[len + 1])
        len++;
    for (int i = len; i >= 1; --i)
        cout << cr[i];
    cout << endl;
    return 0;
}
上一篇:Mysql 存储过程中使用游标循环读取临时表


下一篇:Java集合Collection&Iterator