poj2389 Bull Math
来源:互联网 发布:高仿人民币淘宝支付 编辑:程序博客网 时间:2024/06/05 16:40
题目链接:http://poj.org/problem?id=2389
题意:给你两个数,让你输出相乘的结果
解析:高进度乘法,c++用数组来模拟,java用BigInteger
#include <string>#include <cstring>#include <cstdio>#include <iostream>using namespace std;const int maxn = 1205;int a[maxn],b[maxn];int c[maxn];int main(void){ string t1,t2; cin>>t1>>t2; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); a[0] = t1.length(),b[0] = t2.length(); for(int i=1;i<=a[0];i++) a[i] = t1[a[0]-i] - '0'; for(int i=1;i<=b[0];i++) b[i] = t2[b[0]-i] - '0'; int lenc = 1,x = 0; for(int i=1;i<=a[0];i++) { x = 0; for(int j=1;j<=b[0];j++) { c[i+j-1] = a[i]*b[j]+x+c[i+j-1]; x = c[i+j-1]/10; c[i+j-1]%=10; } c[i+b[0]] = x; } lenc = a[0]+b[0]; while(c[lenc]==0 && lenc>1) lenc--; for(int i=lenc;i>=1;i--) printf("%d",c[i]); puts(""); return 0;}
import java.math.BigInteger;import java.util.Scanner;public class Main{ public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigInteger a = cin.nextBigInteger(); BigInteger b = cin.nextBigInteger(); BigInteger ans = a.multiply(b); System.out.println(ans); cin.close(); }}
阅读全文
0 0
- POJ2389:Bull Math
- POJ2389 Bull Math
- [高精度] Poj2389 Bull Math
- POJ2389 Bull Math【大数】
- poj2389 Bull Math
- poj2389——Bull Math
- poj2389 Bull Math(大数java)
- 【POJ2389】Bull Math(大数乘法)
- POJ2389《Bull Math》方法:高精度 模拟
- poj2389 Bull Math (高精度之A*B)
- Bull Math
- poj 2389 Bull Math
- Bull Math
- POJ 2389 Bull Math
- Bull Math(P2389)
- POJ 2389 Bull Math
- NOJ [1126] Bull Math
- Bull Math(高精度)
- Android UI 小红点 可拖拽删除
- 数据结构 — 二叉树的基本操作实现(递归算法)
- POJ 1995 Raising Modulo Numbers 快速幂
- AES加解密
- 重新配置出错eclipse
- poj2389 Bull Math
- linux下安装tomcat8
- MySQL系列—服务器安装与配置
- leetcode 99. Recover Binary Search Tree
- 系统权限管理设计
- Windows10下安装TensorFlow GPU版 及遇到的问题解决办法
- 有效的括号序列
- 【虚拟机搭建Zookeeper Cluster】(一)——在Ubuntu上安装JDK
- JavaScript引擎、虚拟机、运行时环境浅析