#include <cstring>
#include <cstdio>
using namespace std;
char a[3005], b[3005];
int c[3005], d[3085], z[6085], x, y;
void f(char h[], int *t, int len){int i;for(i=1;i<=len;i++) t[i]=h[len-i]-48;}
int main(){
int i, j;
scanf("%s%s", a, b);
x = strlen(a); y = strlen(b);
f(a,c,x); f(b,d,y);
for(i = 1; i <= x; i++)
for(j = 1; j <= y; j++)
z[i+j-1] += c[i]*d[j];
for(i = 1; i <= x+y-1; i++) z[i+1] += z[i]/10, z[i]%=10;
if(!z[i]) i--;
for(j = z[i]?i:i-1; j >= 1; j--) printf("%d",z[j]);
return 0;
}
上面是乘法下面是加法
#include <cstring>
#include <cstdio>
using namespace std;
char a[385], b[385];
int c[385], d[385], x, y;
int main(){
int i, j, n, m;
scanf("%s%s", a, b);
n = (x = strlen(a))>(y = strlen(b))?x:y;
for(i = 0; i < n; i++){
c[i] += (a[x-i-1]-48)>0?a[x-i-1]-48:0; d[i] += (b[y-i-1]-48)>0?b[y-i-1]-48:0;
c[i] += d[i]; c[i+1] += c[i]/10; c[i] %= 10;
}
for(j = c[n]?n:n-1; j >= 0; j--) printf("%d", c[j]);
return 0;
}