有人知道为什么python数值计算这么厉害么?
查看原帖
有人知道为什么python数值计算这么厉害么?
288506
OutsideR_楼主2020/12/30 16:21

python水码

print(int(input())+int(input()))

C++的开心高精度

#include <iostream>
#include <string> 
using namespace std;
void stoi(int a[],string a2){
	a[0]=a2.length();
	for(int i = 1;i<=a[0];i++)a[i]=a2[a[0]-i]-'0';
}
int a[2000],b[2000],c[2000];
string str1,str2;
int main(){
	cin>>str1>>str2;
	stoi(a,str1);
	stoi(b,str2);
	c[0]=max(a[0],b[0]);
	int x=0;
	for(int i =1;i<=c[0];i++){
		c[i]=a[i]+b[i]+x;
		x=c[i]/10;
		c[i]%=10;
	}
	if(x>0){
		c[0]++;
		c[c[0]]=x;
	}
	for(int i = c[0];i>=1;i--)cout<<c[i];
	cout<<endl;
	return 0;
} 
2020/12/30 16:21
加载中...