后两个点,大佬们
  • 板块P1303 A*B Problem
  • 楼主Yzmddsw
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/10/29 12:40
  • 上次更新2023/11/4 02:01:26
查看原帖
后两个点,大佬们
540870
Yzmddsw楼主2021/10/29 12:40

本人学了一周,代码写的不好

#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
char a[3000],b[3000];
int main()
{	
	cin>>a>>b;
	if(a[0]=='0'||b[0]=='0')
	{
		cout<<0;
		return 0;
	}
	int stra,strb;
	string m=a;
	string n=b;
	int k=0,s=-1;
	int ans[900000000];
	int e=m.length();
	//cout<<m.length()<<n.length();
	if(n.length()>e)e=n.length();
	for(int i=m.length();i>0;i--)
	{
		s++;
		k=s;
		for(int j=n.length();j>0;j--)
		{
			ans[k]+=((a[i-1]-'0')*(b[j-1]-'0'))%10;
			ans[k+1]+=((a[i-1]-'0')*(b[j-1]-'0'))/10;
			if(ans[k]>=10)
			{
			ans[k+1]++;
			ans[k]=ans[k]%10;
			}
			k++;
		}
	}
	if(ans[k]==0)
	{k--;
	}
	for(int j=k;j>=0;j--)
		{
			
			cout<<ans[j];
		}
	return 0; 
}
2021/10/29 12:40
加载中...