求救!!有时候多会输出一个0在前面
查看原帖
求救!!有时候多会输出一个0在前面
408856
比尔008楼主2021/3/12 14:25

求救高精度+

#include <bits/stdc++.h>
using namespace std;
	int d[99999999],mmm,w;
int  a[100],b[100],c[100];
void init(int a[],int b[])
{
    string s,f;
    cin >>s>>f;
	a[0]=s.length();
	b[0]=f.length();
	if(a[0]>b[0])
	{
		mmm=a[0];
	}
	else
	{
		mmm=b[0];
	}
	for(int i=1;i<=a[0];i++)
	{
    	a[i]=s[a[0]-i]-'0';

	}
	for(int j=1;j<=b[0];j++)
	{
    	b[j]=f[b[0]-j]-'0';

	}
	return ;

}
void out(int a[],int b[])
{

	  for(int q=1;q<=mmm;q++)
      {
		d[q]=d[q]+a[q]+b[q];
		if(d[q]>=10)
		{
			d[q+1]+=d[q]/10;
			d[q]=d[q]%10;
		}
	  }
	  if(d[a[0]+1]>0)
	  {
	   for(int e=mmm;e>0;e--)
       {
		cout<<d[e];
	   }
      }
      else if(d[a[0]+1]==0)
      {
       for(int e=mmm+1;e>0;e--)
       {
		cout<<d[e];
	   }
	  }
}
int main()
{
 int a[100000],b[100000];
 init(a,b);
  out(a,b);
 return 0;
}

2021/3/12 14:25
加载中...