Poj OpenJudge 百练 2389 Bull Math
1.Link:
http://poj.org/problem?id=2389
http://bailian.openjudge.cn/practice/2389/
2.Content:
Bull Math
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13067 Accepted: 6736 Description
Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. Farmer John wonders if their answers are correct. Help him check the bulls' answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros).FJ asks that you do this yourself; don't use a special library function for the multiplication.
Input
* Lines 1..2: Each line contains a single decimal number.Output
* Line 1: The exact product of the two input linesSample Input
- 11111111111111
- 1111111111
Sample Output
- 12345679011110987654321
Source
3.Method:
直接套大数相乘模板
http://www.cnblogs.com/mobileliker/p/3516920.html
4.Code:
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- string mul(string str1,string str2)
- {
- vector<int> v_res(str1.size()+str2.size(),);
- string::size_type i,j;
- vector<int>::size_type k,p;
- reverse(str1.begin(),str1.end());
- reverse(str2.begin(),str2.end());
- for(i = ; i != str1.size(); ++i)
- {
- for(j = ; j != str2.size(); ++j)
- {
- v_res[i+j] += (str1[i]-'') * (str2[j] - '');
- }
- }
- for(k = ; k != v_res.size() - ; ++k)
- {
- v_res[k+] += v_res[k] / ;
- v_res[k] = v_res[k] % ;
- }
- for(p = v_res.size() - ; p != -; --p)
- {
- if(v_res[p] != ) break;
- }
- if(p == -) p = ;
- string s_res(p+,'');
- for(k = p; k != -; --k) s_res[p-k] = char(v_res[k] + '');
- return s_res;
- }
- int main()
- {
- //freopen("D://input.txt","r",stdin);
- string str1,str2;
- cin >> str1 >> str2;
- cout << mul(str1,str2) << endl;
- return ;
- }
5.Reference:
Poj OpenJudge 百练 2389 Bull Math的更多相关文章
- Poj OpenJudge 百练 1062 昂贵的聘礼
1.Link: http://poj.org/problem?id=1062 http://bailian.openjudge.cn/practice/1062/ 2.Content: 昂贵的聘礼 T ...
- Poj OpenJudge 百练 1860 Currency Exchang
1.Link: http://poj.org/problem?id=1860 http://bailian.openjudge.cn/practice/1860 2.Content: Currency ...
- Poj OpenJudge 百练 2602 Superlong sums
1.Link: http://poj.org/problem?id=2602 http://bailian.openjudge.cn/practice/2602/ 2.Content: Superlo ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- Poj OpenJudge 百练 Bailian 1008 Maya Calendar
1.Link: http://poj.org/problem?id=1008 http://bailian.openjudge.cn/practice/1008/ 2.content: Maya Ca ...
- poj 2389.Bull Math 解题报告
题目链接:http://poj.org/problem?id=2389 题目意思:就是大整数乘法. 题目中说每个整数不超过 40 位,是错的!!!要开大点,这里我开到100. 其实大整数乘法还是第一次 ...
- POJ 2389 Bull Math(水~Java -大数相乘)
题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...
- Openjudge 百练第4109题
在OpenJudge看到一个题目(#4109),题目描述如下: 小明和小红去参加party.会场中总共有n个人,这些人中有的是朋友关系,有的则相互不认识.朋友关系是相互的,即如果A是B的朋友,那么B也 ...
随机推荐
- C++ C++ 控制台程序 设置图标
. 实现过程 创建1个控制台程序. 新建1个 Resource Script文件 #include "stdio.h" #include <windows.h> #in ...
- delphi CoolBar这个怎么弄没了
CoolBar这个怎么弄没了 像Windows这样的 procedure TForm1.Button1Click(Sender: TObject); begin CoolBar1.Fix ...
- [Angular 2] Understanding OpaqueToken
When using provider string tokens, there’s a chance they collide with other third-party tokens. Angu ...
- 深入探讨this指针
深入探讨this指针 为了写这篇文章,准备了好长时间,翻遍了箱底的书籍.可是如今还是不敢放开手来写,战战兢兢.不是操心自己写错,而是唯恐自己错误误导别人.同一时候也希望这篇文章能给你一点收获.既然 ...
- Gradient Boost Decision Tree(&Treelink)
http://www.cnblogs.com/joneswood/archive/2012/03/04/2379615.html 1. 什么是Treelink Treelink是阿里集团内部 ...
- php的引用&(就是在变量或者函数、对象等前面加上&符号)
官方文档: 1.引用是什么:http://www.php.net/manual/zh/language.references.whatare.php 2.引用做什么:http://www.php.ne ...
- HBase-初看HBase
0.95版本hbase 单机模式下所有的服务都运行在一个JVM上,包括HBase和zookeeper.使用的是本地文件系统 日志默认放在目录下logs文件夹中 基本命令: create 'table' ...
- SSIS 学习(2):数据流任务(上)【转】
数据流任务是SSIS中的一个核心任务,估计大多数ETL包中,都离不开数据流任务.所以我们也从数据流任务学起. 数据流任务包括三种不同类型的数据流组件:源.转换.目标.其中: 源:它是指一组数据存储体, ...
- Linux上安装MPEG-1 Layer3(mp3)解码器
今天突然想要在linux上播放音乐,但是打开之后发现缺少了解码器 于是去网上找了解决的方法,说得天花乱坠,不过有个帖子给出了很简单的方法. 以下内容转载于网络 上面提示没有安装解码器,这是因为版权问题 ...
- [转]关于IIS7.5下的web.config 404 配置的一些问题
本文转自:http://www.codesky.net/article/201103/161589.html 本文介绍一个关于IIS环境下web.config配置的经验问题.在IIS7.5中添加配置4 ...