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
1111111111Sample Output
12345679011110987654321Source
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也 ...
随机推荐
- Android自定义radiobutton(文字靠左,选框靠右)
<RadioButton android:id="@+id/rb_never" android:layout_width="fill_parent" an ...
- iOS开发——设备篇&ios8文件路径
ios8文件路径 1,之前版本的(比如iOS7)的文件路径如下: app路径 /var/mobile/Applications/59C84B75-0900-43D6-AD6F-AB9731F064 ...
- #define使用方法
1.简单的define定义 #define MAXTIME 1000 一个简单的MAXTIME就定义好了,它代表1000,假设在程序里面写 if(i<MAXTIME){.........} 编译 ...
- SIGGRAPH 2014 之行
当地时间8月8号: 经历十个多小时的飞行,在紧急出口旁的位置上忍受发动机的轰鸣声后,顺利降落温哥华机场.回答完加拿大边检的几个诸如为何而来,打算住哪儿的问题后,比较顺利出关.三十五加元的打车费及百分十 ...
- HTML转换成word文档
1工具类保存word文件 public class WordAction { public static void SaveAsWord(string fileName, string pFileNa ...
- Spark之路 --- Windows Scala 开发环境安装配置
JDK安装 JDK安装包下载 到Oracle官网下载JDK. 传送门 下载之前要记得勾选上同意协议然后选择相应的版本(Windows/Linux, 32/64) JDK安装及验证 按提示完成安装,安装 ...
- c语言全局变量
1.全局变量 #include <stdio.h> int L,n; void solve() { // printf("%d",L); printf("%d ...
- linux用户及组管理
useradd 添加用户 passwd 修改用户密码 userdel 删除用户,默认不删除用户主目录和email,如果想删除可加 –r 参数 groupadd 添 ...
- Windows 平台下Git 服务器搭建
由于项目中一直在使用git作为版本管理,自己对git的理解.使用都还不是怎么的熟悉,所以准备深入了解一下git及一些常用命令的使用,于是干脆把服务端架上,通过自己的PC作为服务端同时作为客户端的角色进 ...
- 转: android studio 消除SDK更新时的“https://dl-ssl.google.com refused”错误
消除了: hostname in certificate didn't match: 转: http://blog.csdn.net/gaojinshan/article/details/987160 ...