20pts,AC on #1
  • 板块P1303 A*B Problem
  • 楼主Kinzo
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/2/15 20:11
  • 上次更新2023/10/24 00:42:06
查看原帖
20pts,AC on #1
796550
Kinzo楼主2023/2/15 20:11
#include <bits/stdc++.h>
using namespace std;

int a[2010],b[2010],ans[4020];
int lena,lenb,pos=-1;
string stra,strb;

void length(int &len,string str) {
	len=str.size();
}

void change(int len,string str,int *p) {
	for(int i=1; i<=len; i++) {
		p[i]=str[len-i-1]-48;
	}
}

void init() {
	cin>>stra>>strb;
	length(lena,stra);
	length(lenb,strb);

	change(lena,stra,a);
	change(lenb,strb,b);
}

void count() {
	for(int i=1; i<=lena; i++) {
		for(int j=1; j<=lenb; j++) {
			ans[i+j-1]=a[i]*b[j];
		}
	}
}

void carry() {
	for(int i=1; i<=lena+lenb; i++) {
		ans[i+1]+=ans[i]/10;
		ans[i]%=10;
	}
}

void del_0() {
	for(int i=lena+lenb; i>=1; i--) {
		if(ans[i]>=1){
			pos=i;
			break;
		}
	}
}

void output(){
	for(int i=pos;i>=1;i--){
		cout<<ans[i];
	}
}

void judg(){
	if(pos==-1){
		cout<<0;
	}
}

void end(){
	cout<<endl; 
//	system("pause");
}

int main() {
	init();

	count();

	carry();
	
	del_0();
	
	output();
	
	judg();
	
	end();
	
	return 0;
}
2023/2/15 20:11
加载中...