emm……关于高精的事:高精加,高精乘,高精减……

emm……这一篇主要是用来记录所有的高精之类的东西的……

首先:高精加!!!

 高精加的难点就是算法和倒置和去除前导0。

 直接上代码:

#include
#include
#include
int main()
{
	char a_str[255],b_str[255];
	gets(a_str);
	gets(b_str);
	int lena=strlen(a_str);
	int lenb=strlen(b_str);
	
	int a[255],b[255],c[255];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i1)
		lenc--;
	for(int i=lenc;i>=1;i--)
		printf("%d",c[i]);
	return 0;
}
好的,就大概是这样了,高精加的精髓在于算法,一定要理解!!!

接着!!!

高精减

 高精减的难度就只有它的算法是精髓,其他的跟高精乘差不多…………

#include
#include
#include
#include
using namespace std;
int main()
{
	char a_str[255],b_str[255],t[255];//b=n2
	gets(a_str);
	gets(b_str);
	if(strlen(a_str)1)
	{
		lenc--;
	}
	for(int i=lenc;i>=1;i--)
	{
		printf("%d",c[i]);
	}
	return 0;
}

高精乘

#include
#include
#include
#include
int main()
{
	char a_str[210],b_str[210];
	gets(a_str);
	gets(b_str);
	if(a_str[0]=='-'&&b_str[0]!='-'){
		a_str[0]='0';
		printf("-");}
	if(b_str[0]=='-'&&a_str[0]!='-'){
		b_str[0]='0';
		printf("-");}
	if(b_str[0]=='-'&&a_str[0]=='-'){
		a_str[0]='0';
		b_str[0]='0';}
	int lena=strlen(a_str);
	int lenb=strlen(b_str);
	
	int a[210],b[210],c[410];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i1)
		--lenc;
	for(int i=lenc;i>=1;i--)
		printf("%d",c[i]);
	return 0;
}

高精除

这里申明一下,是高精除低精~

#include
#include
#include
#include
using namespace std;
int b;
int main()
{
	char a1[100],c1[100];
	int a[100],c[100],lena,i,x=0,lenc;
	memset(a,0,sizeof(a));
	memset(c,0,sizeof(c));
	gets(a1);
	cin>>b;
	lena=strlen(a1);
	for(i=0;i<=lena-1;i++)
		a[i+1]=a1[i]-48;
	for(i=1;i<=lena;i++)
	{
		c[i]=(x*10+a[i])/b;
		x=(x*10+a[i])%b;
	}
	lenc=1;
	while(c[lenc]==0&&lenc




你可能感兴趣的:(必须明白)