/*
POJ2389 Bull Math
http://poj.org/problem?id=2389
高精度乘法
*
*/
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int Nmax=;
struct BigInt
{
int a[Nmax];
int n;
void init()
{
for(int i=;i<Nmax;i++)
a[i]=;
}
BigInt()
{
init();
n=;
}
BigInt(int _a[],int _n)
{
init();
n=_n;
//for(int i=0;i<Nmax;i++)
//a[i]=0;
for(int i=;i<=n;i++)
a[i]=_a[i];
maintain();
}
BigInt(char s[])
{
init();
n=strlen(s+);
for(int i=;i<=n;i++)
a[i]=s[n-i+]-'';
maintain();
}
BigInt(long long x)
{
init();
n=;
while(x>0LL)
{
a[++n]=x%10LL;
x/=10LL;
}
}
BigInt(int x)
{
init();
n=;
while(x>)
{
a[++n]=x%;
x/=;
}
}
void read()
{
init();
n=;
char c=getchar();
if(c==-)
return;
while(c==' ' || c=='\n' )
{
c=getchar();
if(c==-)
break;
}
int num[Nmax];
while(c!=' ' && c!='\n' && c!=-)
{
num[++n]=c-'';
c=getchar();
}
for(int i=;i<=n;i++)
a[i]=num[n-i+];
maintain();
}
void print()
{
if(n==)
printf("");
for(int i=n;i>=;i--)
printf("%d",a[i]);
}
void maintain()
{
for(int i=;i<=n;i++)
{
a[i+]+=a[i]/;
a[i]%=;
}
int j=n+;
while(a[j]!=)
{
a[j+]+=a[j]/;
a[j]%=;
j++;
}
n=j-;
while(a[n]== && n>)
n--;
}
friend BigInt operator + (BigInt a,BigInt b)
{
int len=max(a.n,b.n);
BigInt ans;
ans.n=len;
for(int i=;i<=len;i++)
ans.a[i]=a.a[i]+b.a[i];
ans.maintain();
return ans;
}
//friend BigInt operator - (BigInt a,BigInt b)
//{
//int len=max(a.n,b.n);
//BigInt ans;
//ans.n=len;
//for(int i=1;i<=len;i++)
//ans.a[i]=a.a[i]-b.a[i];
//for(int i=1;i<=len;i++)
//{
//if(ans.a[i]<0)
//{
//ans.a[i]+=10;
//a.a[i+1]--;
//}
//ans.a[i]+=10
//}
//}
friend BigInt operator * (BigInt b,int a)
{
int n=b.n;
BigInt ans;
ans.n=n;
for(int i=;i<=n;i++)
ans.a[i]=b.a[i]*a;
ans.maintain();
return ans;
}
friend BigInt operator * (int a,BigInt b)
{
int n=b.n;
BigInt ans;
ans.n=n;
for(int i=;i<=n;i++)
ans.a[i]=b.a[i]*a;
ans.maintain();
return ans;
}
friend BigInt operator * (BigInt a,BigInt b)
{
BigInt ans;
ans.n=a.n+b.n+;
int k;
for(int i=;i<=a.n;i++)
for(int j=;j<=b.n;j++)
ans.a[j+i-]+=a.a[i]*b.a[j];
ans.maintain();
return ans;
}
};
int main()
{
char s[];
char s1[];
BigInt a,b;
//freopen("test.in","r",stdin);
a.read();
b.read();
(a*b).print();
printf("\n");
return ;
}

POJ2389 Bull Math的更多相关文章

  1. POJ2389 Bull Math【大数】

    Bull Math Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15040   Accepted: 7737 Descri ...

  2. Poj OpenJudge 百练 2389 Bull Math

    1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...

  3. BZOJ1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 374  Solved: 227[Submit ...

  4. 1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 398  Solved: 242[Submit ...

  5. POJ 2389 Bull Math(水~Java -大数相乘)

    题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...

  6. BZOJ 1754: [Usaco2005 qua]Bull Math

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

  7. [PKU2389]Bull Math (大数运算)

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

  8. poj 2389.Bull Math 解题报告

    题目链接:http://poj.org/problem?id=2389 题目意思:就是大整数乘法. 题目中说每个整数不超过 40 位,是错的!!!要开大点,这里我开到100. 其实大整数乘法还是第一次 ...

  9. 【BZOJ】1754: [Usaco2005 qua]Bull Math

    [算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...

随机推荐

  1. 【cl】在代码中查找系统页面中的代码方法

    页面链接http://192.168.2.51:8080/xxcb1/xxbs/action/handling!view.action?toId=402882ae4e7d1761014e877fb22 ...

  2. 使用OpenSSL做RSA签名验证 支付宝移动快捷支付 的server异步通知

    因为业务须要.我们须要使用支付宝移动快捷支付做收款.支付宝给了我们<移动快捷支付应用集成接入包支付接口>见支付宝包<WS_SECURE_PAY_SDK>. 支付宝给的serve ...

  3. Java缓存server调优

    搜索降级方案中xmn開始使用bizer默认的128M,很慢. 偶然改成1G,效果立刻上来,可是xmx调大并没有明显效果.                  100并发             200并 ...

  4. Windows 10彻底关闭自动更新

    关键点:把流量计费开启.

  5. Java-杂项:Float 加减精度问题

    ylbtech-Java-杂项:Float 加减精度问题 1.返回顶部 1. java float 加减精度问题在取这个字段的时候转换成BigDecimal就可以了同时,BigDecimal是可以设置 ...

  6. linux系统下块设备驱动程序

    顾名思义,块设备驱动程序就是支持以块的方式进行读写的设备.块设备和字符设备最大的区别在于读写数据的基本单元不同.块设备读写数据的基本单元为块,例 如磁盘通常为一个sector,而字符设备的基本单元为字 ...

  7. python笔记:文件操作

    1.逐行打印整个文件 # -*- coding: utf-8 -*- f = open("test",'r',encoding="utf-8") count = ...

  8. win7如何给虚拟机设置共享文件

    友情提示:设置之前先把虚拟机关掉 1. 安装vmtools 安装过的,则不需要 重新安装 如果没有安装vmware tools,点击安装(需要联网下载) ,下载完成后,打开虚拟机 点击安装,安装完毕后 ...

  9. android 学习记录-----------android 活动 意图 碎片

    将此篇博客作为记录android项目开发过程中的学习记录

  10. B - Guess a number!

    Problem description A TV show called "Guess a number!" is gathering popularity. The whole ...