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也 ...
随机推荐
- USACO prefix TrieTree + DP
/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include &l ...
- Web开发接口测试工具——Postman插件的使用(chrome浏览器)
Postman是chrome浏览器的一款插件.Postman 可以模拟 http 请求的发送,并自动解析 JSON 和 XML 的返回数据. 可以手动的去配置各类 parameter,还支持 Basi ...
- NopCommerce 数据库初始化
NopCommerce数据库初始化比较复杂,我简化了,只初始化创建一张表,不多说,直接上代码: //数据实体 /// <summary> /// Represents an affilia ...
- sqlserver 字符串相关函数
http://www.cnblogs.com/jiajiayuan/archive/2011/06/16/2082488.html 以下所有例子均Studnet表为例: 计算字符串长度len()用来 ...
- Fedora安装
转载:http://www.51ou.com/browse/fedora/33174.html 安装fedora后的20个系统设置 安装VirtualBox增强工具 1.编辑sudoers文件,先备份 ...
- Linux c编程实例_例子
例一:字符与整型变量的实现 #include <stdio.h> int main() { int c1,c2; char c3; c1='a'-'A'; c2='b'-'B'; c3=; ...
- The First
好吧,今天是第一次,写博客,虽然有点不明白,博客的作用.以后就写点感想,与每天的收获.既然,在博客园注册,自然也与IT相关了. hello,world!
- Java中执行外部命令
在项目中执行一个linux的shell脚本,于是需要在java环境下执行外部命令如系统命令.linux命令的需求,本人小小研究了一下,又上网查了一些资料先整理如下. java执行外部命令主要依赖两个类 ...
- struts2.1笔记02:servlet简介
1. Servlet 是在服务器上运行的小程序.这个词是在 Java applet的环境中创造的,Java applet 是一种当作单独文件跟网页一起发送的小程序,它通常用于在客户端运行,结果 ...
- jq宽高 详解
alert($(window).height()); //浏览器时下窗口可视区域高度 alert($(document).height()); //浏览器时下窗口文档的高度 alert($(docum ...