点击这里更换您喜欢的皮肤wtboj 首页
请点击这里登入noios   首页 入门 c++讲义 入门教程视频 金牌教程 入门视频 站务 公告 | 题库 记录 竞测 测试 闯关 作业 排名 团队 讨论 | 换肤 | 登入 注册  
News >>   新增功能:各团队管理员可以发布本团队作业了 ()

From sina007
高精度乘法
讨论 Discussion
 
少于牛鼻
#include <bits/stdc++.h>
using namespace std;
int main(){  
freopen("p1256.in","r",stdin);
freopen("p1256.out","w",stdout);
string sa,sb,t; char s[6];
int a[10001]={0},b[10001]={0},c[21001]={0};
getline(cin,sa);
getline(cin,sb);
int x,y,z,i,j,k;
x=sa.length();y=sb.length();
x=0;
while(sa.length()>2){
t=sa.substr(sa.length()-3,3);
a[++x]=atoi(t.c_str());
sa.erase(sa.length()-3,3);
}
if (sa.length()>0) a[++x]=atoi(sa.c_str());
y=0;
while(sb.length()>2){
t=sb.substr(sb.length()-3,3);
b[++y]=atoi(t.c_str());
sb.erase(sb.length()-3,3);
}
if (sb.length()>0)b[++y]=atoi(sb.c_str());
for(i=1;i<=x;i++)
for(j=1;j<=y;j++)
{
c[i+j-1]+=a[i]*b[j];
c[i+j]+=c[i+j-1]/1000;
c[i+j-1]%=1000;
}
for(int m=x+y+1;m>=0;m--){
if(c[m]>0){k=m;break;}
}
for(i=k;i>=1;i--){
sprintf(s,"%d",c[i]);
if(i!=k) for(int x=1;x<=3-strlen(s);x++)cout<<0;
cout<<c[i];
}
fclose(stdin);
fclose(stdout);
return 0;
}
( )

此主题无回复显示
发布讨论主题 回复讨论主题
Flag
  
题号
  P1256
  其它
通过
  45人
提交
  221次
通过率
  20%
难度
  3
提交 讨论 题解
 Copyright wtboj © 2005-2006. www.wutuobang.date Powered by wtboj 关于 联系 帮助
 wtboj Information ---- Total Users : 1363 | Online Users / Processes : 0 / 80 | Processed Time : 47 ms | Server Time : 2025/12/17 13:46:10