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的更多相关文章

  1. bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】

    高精乘法板子 然而WA了两次也是没救了 #include<iostream> #include<cstdio> #include<cstring> using na ...

  2. 1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 398  Solved: 242[Submit ...

  3. 【BZOJ】1754: [Usaco2005 qua]Bull Math

    [算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...

  4. BZOJ1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 374  Solved: 227[Submit ...

  5. bzoj 1755: [Usaco2005 qua]Bank Interest【模拟】

    原来强行转int可以避免四舍五入啊 #include<iostream> #include<cstdio> using namespace std; int r,y; doub ...

  6. bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】

    --这可能是早年Pascal盛行的时候考排序的吧居然还是Glod-- #include<iostream> #include<cstdio> #include<algor ...

  7. 1755: [Usaco2005 qua]Bank Interest

    1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 187  Solved: 162[Su ...

  8. Poj OpenJudge 百练 2389 Bull Math

    1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...

  9. bzoj1751 [Usaco2005 qua]Lake Counting

    1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 168  Solved: 130 [ ...

随机推荐

  1. 正则表达式 和 junit测试

    需要知道一些常规的正则表达式语句,然后可以仿照规则写出一下正则表达式语句.然后是关于junit测试. 知道了一个之前看过的文档,然后有功夫就看一下那个文档就可以,或者后面找时间搜索一下. 正则表达式是 ...

  2. js中的"=="与"==="的区别

    "==": 1,如果两表达式的类型不同,则试图将它们转换为字符串.数字或 Boolean 量. 2,NaN 与包括其本身在内的任何值都不相等. 3,负零等于正零. 4,null 与 ...

  3. dsoframer控件在64系统上使用问题小汇总

    由于工作中需要,我接触了dsoframer控件,我办公电脑是64系统,在使用时,总是报没有注册类错误.我很是奇怪,dsoframer.ocx控件我都注册过的呀.然后在网上查阅了许多相关资料.悲哀的是, ...

  4. js广告浮动

    一个广告框在指定区域,有定位属性的父级区域内,一直向右向左移动,如果碰到左右边框,反向,如果碰到上下边距,反向,实现在指定框中浮动的效果. <!doctype html> <html ...

  5. 20160420javaweb之文件上传和下载

    一.文件上传 1.提供表单允许用户通过表单选择文件进行上传 表单必须是POST提交 文件输入框必须有name属性,只有有name属性的输入项浏览器才会进行提交 需要设置enctype属性值为multi ...

  6. Servlet相关接口和Servlet的生命周期

    http://www.cnblogs.com/luotaoyeah/p/3860292.html Servlet相关接口和Servlet的生命周期 创建一个Servlet类最直接的方式是实现javax ...

  7. SQL SERVER语句汇总

    1.查询数据库中所有用户表名:用户表总数. select name from dbo.sysobjects where OBJECTPROPERTY(id,N'IsUserTable')=1 sele ...

  8. 用正则表达式解析XML

    import java.util.regex.*; import java.util.*; /** * * <p>Title: Document</p> * * <p&g ...

  9. ios UIWebview本地加载H5网页

    注意两点 1.拖动文件到工程中选择create folder,文件夹为蓝色  --不要让文件参与编译,而只是让文件加入进来 2.加载方式pathforresorth   oftype   indire ...

  10. 关于web项目中中文乱码问题的总结

    关于post和get的中文乱码处理 get: (1)转码:String username=request.getParameter("username");       Strin ...