提交记录 11313


用户 题目 状态 得分 用时 内存 语言 代码长度
ojkiller 1004a. 【模板题】高精度乘法2 Accepted 100 4.037 ms 100 KB C++ 1.86 KB
提交时间 评测时间
2019-11-14 17:04:57 2020-08-01 02:42:10
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define il inline
#define rg register
typedef long long ll;
const int L=2500;
const int p=8;
const int wei=100000000;

char s1[10005],s2[10005];
ll a[L],b[L],c[L];

int chg(char s[],ll n[]){
	char tmp[10];
	int len=strlen(s+1),cur=0;
	while(len>=p){
		strncpy(tmp,s+len-p+1,p);
		n[++cur]=atoi(tmp);
		len-=p;
	}
	if(len){
		memset(tmp,0,sizeof(tmp));
		strncpy(tmp,s+1,len);
		n[++cur]=atoi(tmp);
	}
	return cur;
}
int add(ll a[],ll b[],ll c[],int la,int lb){
	int k=0,lc=max(la,lb);
	for(int i=1;i<=lc;++i){
		c[i]=a[i]+b[i]+k;
		k=c[i]/wei;
		c[i]%=wei;
	}
	if(k) c[++lc]=k;
	return lc;
}
int cmp(ll a[],ll b[],int la,int lb){//1大于 0等于 -1小于 
	//printf("la:%d lb:%d\n",la,lb);
	if(la!=lb) return la>lb? 1:-1;
	for(int i=la;i>=1;--i){//从高位往低位比!!! 
		if(a[i]!=b[i]){
			//printf("a:%d b:%d\n",a[i],b[i]);
			return a[i]>b[i]? 1:-1; 
		}
	}
	return 0;
}
int sub(ll a[],ll b[],ll c[],int la,int lb){
	int lc=max(la,lb);
	for(int i=1;i<=lc;++i){
		c[i]+=a[i]-b[i];
		if(c[i]<0){
			c[i]+=wei;
			--c[i+1];
		}
	}
	while(c[lc]==0&&lc>1) --lc;
	return lc;
}
int mul(ll a[],ll b[],ll c[],int la,int lb){
	for(int i=1;i<=la;++i){
		ll k=0;
		for(int j=1;j<=lb;++j){
			c[i+j-1]+=a[i]*b[j]+k;
			k=c[i+j-1]/wei;
			c[i+j-1]%=wei;
		}
		int f=i+lb-1;
		while(k){
			c[++f]+=k%wei;
			k/=wei;
		}
		if(i==la) return f;
	}
}
void print(ll n[],int len){
	printf("%d",n[len]);
	for(int i=len-1;i>=1;--i){
		printf("%0*d",p,n[i]);
	}puts("");
}
int main(){
	//freopen("fff.out","w",stdout);
	scanf("%s%s",s1+1,s2+1);
	//printf("ls1:%d\n",strlen(s1+1));
	//printf("ls2:%d\n",strlen(s2+1));
	int la=chg(s1,a);
	int lb=chg(s2,b);
	//printf("%d\n",cmp(a,b,la,lb));
	//print(a,la);
	//print(b,lb);
	/*
	int *p1=a,*p2=b;
	if(cmp(a,b,la,lb)==-1){
		printf("-");swap(p1,p2);
	}*/
	int lc=mul(a,b,c,la,lb);
	print(c,lc);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #14.037 ms100 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:45:41 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠