题干:

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= 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

错误代码:(有空看看哪里有问题)

Bull Math

)

#include<bits/stdc++.h>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++) {p=i;c=0;for(int j = 1; j<=len1; j++) {ans[p]+=b[i]*a[j];c=ans[p]/10;ans[p]%=10;while(c>0) {ans[++p] += c%10;//这里是+=!! c/=10;}} for(int i = p; i>=1; i--) {printf("%d",ans[i]);}printf("\n");}for(int i = p; i>=1; i--) {printf("%d",ans[i]);}printf("\n");return 0 ;} //bzoj 1754 [Usaco2005 qua]Bull Math//11111111111111//1111111111

总结:

你在搞笑吗这么简单的模拟你搞了一个小时。。。。逻辑关系能不能理清楚了再敲啊。。。


//  printf("p = %d\n",p);

**【POJ - 2389】 Bull Math (高精度乘法)相关推荐

  1. POJ 2389 Bull Math(FFT)

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

  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. 高精度乘法(正负数皆可(Bull Math)POJ)

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

  5. 【bzoj 1754】【POJ - 2389 】Bull Math (高精度运算)

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

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

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

  7. 算法提高 高精度乘法(java)

    算法提高 高精度乘法 描述 在C/C++语言中,整型所能表示的范围一般为-231到231(大约21亿),即使long long型,一般也只能表示到-263到263.要想计算更加规模的数,就要用软件来扩 ...

  8. 朴素高精度乘法的常数优化

    2015年辽宁省赛热身赛有一道高精度乘法 传送门:NEUOJ 1574 A*B 1574: A * B 时间限制: 10 Sec  内存限制: 128 MB 题目描述 Calculate $a \ti ...

  9. FFT实现高精度乘法

    你应该知道$FFT$是用来处理多项式乘法的吧. 那么高精度乘法和多项式乘法有什么关系呢? 观察这样一个$20$位高精度整数$11111111111111111111$ 我们可以把它处理成这样的形式:$ ...

最新文章

  1. 手机将被小型机器人取代?工程院院士:人工智能技术突破是关键
  2. Spring和Amazon Web Services
  3. Python——使用matplotlib绘制柱状图
  4. 四元数插值方法Slerp/Squad/Spicv/Sping知识总结思维导图
  5. 【渝粤教育】广东开放大学 建筑专业 形成性考核 (57)
  6. 红帽RHEL5U4平台实现pppoe+freeradius+mysql认证服务器(一)
  7. python 累加_对Python实现累加函数的方法详解
  8. python实用性自己设计_用Python设计PCR引物: Primer3-py 初识
  9. 【2016Esri全球用户大会主题亮点】GIS is Getting Smarter——JACK主题演讲权威解读
  10. 去NM的OKR,大坑,得把人逼疯!
  11. 【MILP】Mixed-Integer Quadratic Programming portfolio optimzation
  12. Neural Networks and Deep Learning
  13. 前端面试题及答案(一)
  14. InnoDB关键特性之插入缓冲
  15. 最全面试宝典-我的春招总结
  16. html期末作业代码网页设计——化妆品电商网站(4页) HTML+CSS+JavaScript 使用html+css实现一个静态页面(含源码)
  17. JavaScript 页面资源加载:onload,onerror
  18. linux菜鸡用服务器常用小技巧
  19. 微信小程序之图书借阅系统(含源码+论文+答辩PPT等)
  20. Java需求出发:tk mybatis example

热门文章

  1. [剑指offer]面试题第[58-2]题[JAVA][左旋转字符串][拼接]
  2. POJ 1703 Find them, Catch them 种类并查集
  3. 计算机进去pe怎么设置用户,电脑密码怎么设置,教您设置电脑开机密码
  4. java数字不等于_java – 仅使用set中的数字查找等于或大于给定目标的总和
  5. 867. 分解质因数
  6. linux命令帮助怎么看,Linux命令帮助
  7. matlab 控制实验指导,智能控制系统-实验指导书-实验一-BP算法的MATLAB实现
  8. 爬虫技术python流程图_基于Python的网络爬虫技术研究
  9. win10电脑桌面透明便签_在win10电脑桌面上使用工作跟进提醒办公软件可用哪个便签软件?...
  10. 三个用户在同一系统中同时对他们的c语言,杭州电子科技大学学生考试卷2013年操作系统试卷(2份,有答案)...