蓝桥杯 BASIC 30 高精度加法(大数)

【思路】:大数处理都一样。

【AC代码】:代码细节可以美化一下。

#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>#include <iomanip>using namespace std;#define MAX 100+10int main(){//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);int a[MAX], b[MAX], i = 0, alen = 0, blen = 0;char str[MAX];//initialmemset(a, 0, sizeof(a));memset(b, 0, sizeof(b));//inputcin >> str;alen = strlen(str);for (i = 0; i < alen; i++)a[alen-1-i] = str[i]-'0';cin >> str;blen = strlen(str);for (i = 0; i < blen; i++)b[blen-1-i] = str[i]-'0';//calint temp = 0;for (i = 0; i < (alen>blen?alen:blen); i++){temp = a[i]+b[i]+temp;a[i] = temp % 10;temp = temp / 10;}if (0!=temp)a[i++] = temp;//outputfor (i–; i >=0; i–)cout << a[i];return 0;}

,那段雨骤风狂。人生之旅本就是风雨兼程,是要说曾经拥有,

蓝桥杯 BASIC 30 高精度加法(大数)

相关文章:

你感兴趣的文章:

标签云: