题干:

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

Sample Input

11111111111111
1111111111

Sample Output

12345679011110987654321

解题报告:

好多错误啊一开始写的时候。就是算个大数乘法。

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;const int MAX =1000 + 5 ;
char s1[MAX],s2[MAX];
int a[MAX],b[MAX],ans[MAX];
int len1,len2;
int p,c;//p代表当前位置,c代表进位
int main()
{
//  freopen("in.txt","r",stdin);scanf("%s",s1);scanf("%s",s2);len1=strlen(s1);len2=strlen(s2);//for(int i = 1; i<=len1; i++) {a[len1-(i-1)]=s1[i-1]-'0';}for(int i = 1; i<=len2; i++) {b[len2-(i-1)]=s2[i-1]-'0';}
//  for(int i = len1; i>=1; i--) printf("%d",a[i]);
//  printf("\n");
//  for(int i = len2; i>=1; i--) printf("%d",b[i]);
//  printf("\n");for(int i = 1; i<=len2; i++) {for(int j = 1; j<=len1; j++) {ans[i+j-1] += b[i]*a[j];} }for(int i = 1; i<=len1+len2; i++) {p=i;if(ans[i]<=9) continue;
//      c=ans[i]/10;
//      while(c>0) {
//          ans[++p] += c;
//          ans[p-1]=ans[p-1]%10;
//          c= ( c+ans[p] )/10;
//
//      }while(ans[i]>9) {ans[i]-=10;ans[i+1]++;} }//    printf("p = %d\n",p);for(int i = len1+len2; i>=1; i--) {if(ans[i]!=0) {p=i;break;}}for(int i = p; i>=1; i--) {printf("%d",ans[i]);}printf("\n");return 0 ;} //bzoj 1754 [Usaco2005 qua]Bull Math//11111111111111//1111111111

【bzoj 1754】【POJ - 2389 】Bull Math (高精度运算)相关推荐

  1. [高精度乘法]BZOJ 1754 [Usaco2005 qua]Bull Math

    模板题目,练练手~ #include <iostream> #include <algorithm> #include <cstring> #include < ...

  2. POJ 2389 Bull Math(水~Java -大数相乘)

    题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: 1 import java. ...

  3. POJ 2389 Bull Math(大数乘大数)

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

  4. POJ 2389 Bull Math(FFT)

    Description 给出两个数A和B,求A*B Input 两个数字串,串长均不超过40 Output 输出两个串所表示数字的乘积 Sample Input 11111111111111 1111 ...

  5. **【POJ - 2389】 Bull Math (高精度乘法)

    题干: Bulls are so much better at math than the cows. They can multiply huge integers together and get ...

  6. 高精度乘法(正负数皆可(Bull Math)POJ)

    描述 高精度乘法 输入:两行,每行表示一个非负整数(不超过10000位) 输出:两数的乘积. 样例1 样例输入1 99 101 样例输出1 9999 #include<iostream> ...

  7. poj2389 Bull Math (高精度之A*B)

    题目来源:poj2389 Bull Math Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13350   Accepted ...

  8. java中小数的处理:高精度运算用bigDecimal类,精度保留方法,即舍入方式的指定

    java中小数的处理:高精度运算用bigDecimal类,精度保留方法,即舍入方式的指定 2016年05月11日 11:20:08 阅读数:6336 一. 计算机的小数计算一定范围内精确,超过范围只能 ...

  9. 关于__int128高精度运算

    参考文章 使用__int128可以实现高精度运算,但是这种大整数无法使用函数printf输出结果,所以需要手写输出 #include <bits/stdc++.h> using names ...

最新文章

  1. SQL Server (MSSQLSERVER) 服务因 2148081668 服务性错误而停止。
  2. Oracle 重复数据查询以及删除
  3. 设计模式(24)-----责任链模式
  4. 2017-5-4 进程
  5. Docker 部署 postgresql 与 pgadmin4
  6. java+多线程菜鸟_java多线程
  7. python类的属性和对象属性_Python打印对象的全部属性
  8. 面试经常问的:mybatis的执行流程(比较简洁)
  9. 大整数乘法——分治算法的时间复杂度
  10. python dict遍历_Python专题——详解enumerate与zip用法
  11. 2020年开始,中国程序员前景一片灰暗,是这样吗?
  12. Ubuntu+OpenCV学习汉字点阵,图片打印汉字
  13. 面试中单例模式有几种写法
  14. matplotlib画三维图
  15. 国产手机 不只是老罗一张嘴
  16. 掉入黑洞会怎样?被拉成面条,还是前往另一个宇宙?
  17. java中的char_java中的char是什么意思?
  18. php微信退款aes,关于微信支付退款req_info字段解密问题
  19. 利用pyecharts绘制新浪微博传播图(文末附完整代码地址)
  20. 安全日志分析的五种类型

热门文章

  1. 杜克大学计算机硕士要几年,2017杜克大学春季不招计算机专业的硕士?
  2. linux分割图片软件,桌面应用|5 种拆分 Linux 终端的方法
  3. elementui图片上传php,vue+element-ui+富文本————图片上传
  4. 清零 css,css样式清零及常用类
  5. c语言在函数中传递指针,[求助]关于文件指针在函数中传递的问题
  6. mysql常用命令英文词汇_MySQL中文全文索引插件 mysqlcft 1.0.0 安装使用文档
  7. cmap参数 plt_plt.imshow的参数有哪些?
  8. python电子英汉词典显示_python网页抓取之英汉字典
  9. cubieboard 将linux debian 系统灌入Nand中的操作记录
  10. nginx指定配置文件启动_NGINX安全加固手册