高精度加法(裸)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<memory.h>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int a[10100],b[10100],c[10100];
char temp[30000];
while(cin>>temp)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
while (temp[a[0]] != '\0')
a[0]++;
for (int i = 0; i < a[0]; ++ i)
a[a[0]-i] = temp[i] - 48;
cin>>temp;
while (temp[b[0]] != '\0')
++b[0];
for (int i = 0; i < b[0]; ++ i)
b[b[0]-i] = temp[i] - 48;
c[0] = max(a[0],b[0]);
int x = 0;
for (int i = 1; i <= c[0]; ++ i)
{
c[i] = a[i] + b[i] + x;
x = c[i] / 10;
c[i] %= 10;
}
if (x != 0)
{
c[0]++;
c[c[0]] = x;
}
for (int i= c[0]; i > 0; -- i)
printf("%d",c[i]);
printf("\n");
}
return 0;
}
用来留档,最近用的比较多(:зゝ∠)