原理:竖式计算

注意:倒序存储

加/减法

模版(加,减差不多)

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct sd{
	int d[300], len;
}a, b;
sd read_num();
sd Plus(sd, sd);
void print(sd);
int main()
{
	a = read_num(), b = read_num();
	a = Plus(a, b);
	print(a);
	return 0;
}
sd read_num()
{
	sd x;
	memset(x.d, 0, sizeof(x.d));
	char s[300];
	cin >> s;
	x.len = strlen(s);
	int k = 0;
	for(int i=x.len-1; i>=0; --i)
		x.d[k++] = s[i]-'0';
	return x;
}
sd Plus(sd x, sd y)
{
	sd t;
	memset(t.d, 0, sizeof(t.d));
	int len = x.len>y.len?x.len:y.len;
	//printf("%d\n", len);
	for(int i=0; i<len; ++i)
	{
		//printf("%d %d\n", x.d[i], y.d[i]);
		t.d[i] += x.d[i]+y.d[i];
		//printf("%d ", (int)t.d[i]);
		t.d[i+1] = t.d[i]/10;
		//printf("%d ", (int)t.d[i+1]);
		t.d[i] = t.d[i]%10;
		//printf("%d\n", (int)t.d[i]);
	}
	if(t.d[len] > 0)
		t.len = len+1;
	else
		t.len = len;
	return t;
}
void print(sd x)
{
	for(int i=x.len-1; i>=0; --i)
		printf("%d", (int)x.d[i]);
	return;
}

乘法

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct sd{
	int d[300], len;
}a, b;
sd read_num();
sd Mult(sd, sd);
void print(sd);
int main()
{
	a = read_num(), b = read_num();
	a = Mult(a, b);
	print(a);
	return 0;
}
sd read_num()
{
	sd x;
	memset(x.d, 0, sizeof(x.d));
	char s[300];
	cin >> s;
	x.len = strlen(s);
	int k = 0;
	for(int i=x.len-1; i>=0; --i)
		x.d[k++] = s[i]-'0';
	return x;
}
sd Mult(sd x, sd y)
{
	sd t;
	memset(t.d, 0, sizeof(t.d));
	//int len = x.len>y.len?x.len:y.len;
	//printf("%d\n", len);
	for(int i=0; i<x.len; ++i)
	{
		int temp = 0;
		for(int j=0; j<y.len; ++j)
		{
			t.d[i+j] = x.d[i]*y.d[j]+temp+t.d[i+j];
			temp = t.d[i+j]/10;
			t.d[i+j] %= 10;
		}
		t.d[i+y.len] = temp;
	}
	t.len = x.len+y.len;
	return t;
}
void print(sd x)
{
	while(x.d[x.len-1]==0 && x.len>0)
		--x.len;
	for(int i=x.len-1; i>=0; --i)
		printf("%d", (int)x.d[i]);
	return;
}

#除法

高精除以低精


高精除以高精