• 高精度加法模板


     1 //前提:对于不会超时的题,写得越快,越不容易错越好
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <list>
     7 #include <stack>
     8 #include <vector>
     9 #include <set>
    10 #include <map>
    11 #include <queue>
    12 #include <algorithm>
    13 #include <iostream>
    14 using namespace std;
    15 const long maxn=10000;
    16 long a[maxn+1]={0},b[maxn+1]={0};
    17 char str[maxn+1];
    18 
    19 int main()
    20 {
    21     long lena,lenb,i;
    22     gets(str);
    23     lena=strlen(str);
    24     for (i=0;i<lena;i++)
    25         a[lena-i]=str[i]-48;
    26         
    27     gets(str);
    28     lenb=strlen(str);
    29     for (i=0;i<lenb;i++)
    30         b[lenb-i]=str[i]-48;
    31         
    32     for (i=1;i<=max(lena,lenb);i++)
    33     {
    34         a[i]+=b[i];
    35         a[i+1]+=a[i]/10;
    36         a[i]%=10;
    37     }
    38     if (a[i]==0)
    39         i--;
    40     while (i)
    41     {
    42         printf("%ld",a[i]);
    43         i--;
    44     }
    45     return 0;
    46 }
    47 /*
    48 0
    49 0
    50 0
    51 
    52 9999
    53 1
    54 10000
    55 
    56 1
    57 9999
    58 10000
    59 
    60 12
    61 789
    62 801
    63 
    64 123456789123456789
    65 123456789123456789
    66 246913578246913578
    67 */
  • 相关阅读:
    python之简单爬虫
    python之正则表达式
    python之面向对象
    python之模块与包
    python之循环嵌套与算法
    linux shell实现从函数返回数组
    linux脚本实现数组值相加
    linux中使用函数输出
    linux shelll中显示的意义
    lsof命令
  • 原文地址:https://www.cnblogs.com/cmyg/p/8839244.html
Copyright © 2020-2023  润新知