大数乘法(C++)
来源:互联网 发布:unity3d文件如何打开 编辑:程序博客网 时间:2024/05/22 13:11
题目:POJ 2398
Bull Math
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13410 Accepted: 6903
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.
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
111111111111111111111111
Sample Output
12345679011110987654321
Source
USACO 2004 November
#include<iostream>#include<cstring>#include<cstdio>#include<string>using namespace std;const int maxn = 100;void reverse(char a[]){ int len = strlen(a); for(int i = 0 ; i < len / 2; i++) { int temp = a[i]; a[i] = a[len - i - 1]; a[len - i -1] = temp; }}int main(){ char a[maxn],b[maxn]; int t[100] = {0}; //printf("Please enter 2 numbers: "); scanf("%s%s",a,b); reverse(a); reverse(b); if(strcmp(a,"0")==0||strcmp(b,"0")==0) cout<<"0"<<endl; else { int i,j; for(i = 0; i <strlen(b); i++) { int cnt = 0; for(j = 0; j < strlen(a); j++) { int temp = (b[i] - '0') * (a[j] - '0'); int tt= t[i+j] + temp + cnt; t[j+i] = tt % 10; cnt = tt / 10; } while(cnt != 0) { t[j+i] = cnt % 10; cnt = cnt / 10; j++; } } for(int k = i + j - 2; k >= 0; k--) { cout<<t[k]; } } return 0;}
0 0
- 大数乘法(C++)
- Bigint Multiplication:大数乘法(hihoCoder C++)
- c语言-大数乘法(16进制)
- 大数乘法 C语言
- 大数乘法C实现
- C语言大数乘法
- 大数 乘法 C语言
- c语言大数乘法
- c语言-大数乘法
- 大数乘法(大数乘小数)c语言版
- C语言 乘法 大数相乘
- 大数乘法(模版)
- Product(大数乘法)
- 大数乘法(一)
- 大数乘法(二)
- 大数乘法(模板)
- 大数乘法(转载:通过C语言数组模拟)
- 大数乘法(加法)运算
- UNIX高手的20个习惯
- Oracle Database Server Architecture: Overview
- DS1302组件
- Unity3D 一些基础的3D图形学算法
- 11. PHP String 字符串
- 大数乘法(C++)
- FragmentPagerAdapter与FragmentStatePagerAdapter区别
- sql:MySql create FUNCTION,VIEW,PROCEDURE
- nodejs中mysql用法
- ios-day19-02(GCD介绍。串行队列、并行队列、全局队列、主队列、同步任务、异步任务)
- Makefile函数整理
- sql:MySql create FUNCTION,VIEW,PROCEDURE
- Java中console返回的密码为什么要用数组来存放,而不是字符串
- svn自动过滤文件的问题