问关于高精度
  • 板块灌水区
  • 楼主fanxing1124
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/9/30 21:31
  • 上次更新2024/10/1 08:38:53
查看原帖
问关于高精度
778970
fanxing1124楼主2024/9/30 21:31

这样写高精度有什么弊端吗

#include<bits/stdc++.h>
using namespace std;
int n;
string operator+(string st1,string st2)
{
	int l1=st1.size(),l2=st2.size();
	string st;
	while(l1<l2)l1++,st1='0'+st1;
	int bf=0;
	for(int i=l2-1;i>=0;i--)
	{
		st=char((bf+(st1[i]-'0')+(st2[i]-'0'))%10+'0')+st;
		bf=(bf+(st1[i]-'0')+(st2[i]-'0'))/10;
	}
	if(bf==1)st='1'+st;
	return st;
}
int main()
{
	string st1,st2;
	cin>>st1>>st2;
	cout<<st1+st2<<endl;
	return 0;
}
2024/9/30 21:31
加载中...