BZOJ 1754: [Usaco2005 qua]Bull Math
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 lines
题解:
高精度乘法即可。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
//by zrt
//problem:
using namespace std;
char a[105],b[105];
int c[105];
int la,lb;
int cc;
int stk[105],top;
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
scanf("%s%s",a,b);
la=strlen(a);
lb=strlen(b);
for(int i=0;i<la;i++) a[i]-='0';
for(int i=0;i<lb;i++) b[i]-='0';
for(int i=0;i<la/2;i++) swap(a[i],a[la-i-1]);
for(int i=0;i<lb/2;i++) swap(b[i],b[lb-i-1]);
for(int i=0;i<la;i++){
for(int j=0;j<lb;j++){
c[i+j]+=a[i]*b[j];
}
}
for(int i=0;i<=100;i++){
stk[top++]=(c[i]+cc)%10;
cc=(c[i]+cc)/10;
}
while(stk[top-1]==0) top--;
while(top){
printf("%d",stk[--top]);
}
puts("");
return 0;
}
BZOJ 1754: [Usaco2005 qua]Bull Math的更多相关文章
- bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】
高精乘法板子 然而WA了两次也是没救了 #include<iostream> #include<cstdio> #include<cstring> using na ...
- 1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 398 Solved: 242[Submit ...
- 【BZOJ】1754: [Usaco2005 qua]Bull Math
[算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...
- BZOJ1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 374 Solved: 227[Submit ...
- bzoj 1755: [Usaco2005 qua]Bank Interest【模拟】
原来强行转int可以避免四舍五入啊 #include<iostream> #include<cstdio> using namespace std; int r,y; doub ...
- bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】
--这可能是早年Pascal盛行的时候考排序的吧居然还是Glod-- #include<iostream> #include<cstdio> #include<algor ...
- 1755: [Usaco2005 qua]Bank Interest
1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 187 Solved: 162[Su ...
- Poj OpenJudge 百练 2389 Bull Math
1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...
- bzoj1751 [Usaco2005 qua]Lake Counting
1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec Memory Limit: 64 MB Submit: 168 Solved: 130 [ ...
随机推荐
- javascript笔记08:javascript的if...else语句
案例代码如下: <!DOCTYPE html> <html> <body> <p>点击这个按钮,获得基于时间的问候.</p> <but ...
- webstom 如何获取github上面的项目工程
需要你配好webstorm的github相关的配置,安装好git.exe; 如何配置请参考: webstorm 如何配置git 这个点击github后 会有个提示框 如下图: 如果没有成功,会弹出下面 ...
- Apache Avro 与 Thrift 比较
http://www.tbdata.org/archives/1307 Avro和Thrift都是跨语言,基于二进制的高性能的通讯中间件. 它们都提供了数据序列化的功能和RPC服务. 总体功能上类似, ...
- C#中params使用
1.参数被params修饰即为可变参数,params只能修饰一维数组. 2.给可变参数赋值的时候,可以直接传递数组的元素. 3.在调用的时候,会自动将这些元素封装为一个数组,并将数组传递. 4.可变参 ...
- Ajax编程技术
AJAX:”Asynchronous JavaScript and XML” 中文意思:异步JavaScript和XML. 指一种创建交互式网页应用的网页开发技术. 不是指一种单一的技术,而是有机地利 ...
- 20151210 Jquery 学习笔记 AJAX 进阶
一.加载请求 在 Ajax 异步发送请求时,遇到网速较慢的情况,就会出现请求时间较长的问题.而超 过一定时间的请求,用户就会变得不再耐烦而关闭页面.而如果在请求期间能给用户一些提 示,比如:正在努力加 ...
- c语言指针字符串与字符数组字符串的区别
#include <stdio.h> int main() { //字符串常量,存放于内存常量区. //常量区区的内存具有缓存机制, //当不同指针指向的常量值相同时, //其实这些指针指 ...
- CDT 错误 Cannot run program "gcc"
Eclipse+CDT 编辑C/C++程序出错误: 出现编译错误: **** Rebuild of configuration Debug for project example **** **** ...
- VIM 及正则表达式
VIM及正则表达式 一.查找/Search + 统计 1.统计某个关键字 方法是:%s:keyword:&:gn. 其中,keyword是要搜索的关键字,&表示前面匹配的字符串,n表示 ...
- SQL的定义与使用
一.SQL的定义 SQL(structured query language)即结构化查询语句,是关系数据库的标准语言. SQL的特点有: 1.综合统一 SQL集数据定义语言DDL.数据操作语言DML ...