/*
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. APP漏洞自动化扫描专业评测报告(上篇)

    一.前言 随着Android操作系统的快速发展,运行于Android之上的APP如雨后春笋般涌现.由于一些APP的开发者只注重APP业务功能的实现,对APP可能出现安全问题不够重视,使得APP存在较多 ...

  2. Windows 平台下 Go 语言的安装和环境变量设置

    1. Go 语言 SDK 安装包下载和安装 最新稳定版 1.5.3 安装包 go1.5.3.windows-amd64.msi下载地址 https://golang.org/dl/,大小约 69 MB ...

  3. Date and time types

    https://docs.microsoft.com/en-us/sql/t-sql/data-types/date-and-time-types date (Transact-SQL)datetim ...

  4. I NEED A OFFER!(hdoj--1203--01背包)

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. 【NOIP 2011】 Mayan游戏

    [题目链接] https://www.luogu.org/problemnew/show/P1312 [算法] 深度优先搜索 [代码] #include<bits/stdc++.h> us ...

  6. 2014/09/20 关于ArrayList的几种操作

    1.删除ArrayList集合元素 删除ArrayList集合里面的元素时,提供了Clear方法,Remove方法,RmoveAt方法和RemoveRange方法. Clear方法是移除所有的元素 R ...

  7. kubernetes系列(小知识):kubectl命令自动补全

    kubectl命令自动补全 linux系统 yum install -y bash-completion source /usr/share/bash-completion/completions/d ...

  8. ubuntu的home目录下,Desktop等目录消失不见

    第一步:创建相应的文件夹 首先当然是创建几个相应的英文文件夹喽,比如:Desktop.Downloads. Documents. Music. Pictures. Videos  , Template ...

  9. Solr.NET快速入门(七)【覆盖默认映射器,NHibernate集成】

    覆盖默认映射器 默认情况下,SolrNet使用属性映射Solr字段. 但是,您可能需要使用另一个映射程序. 替换默认映射器取决于您如何设置库: 内置容器 如果使用默认的内置容器,可以在调用Startu ...

  10. DELPHI调试出现disconnected session的解决办法

    我在控制面板中,是禁用了UAC的,如下图 但是,在注册表中启用了UAC(EnableLUA), 工程中请求了管理员权限,如下图: 所以,整个权限请求混乱了. 解决办法,要么把注册表的LUA设置为0,要 ...