直接上代码了:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b) using namespace std; char s[50];
int a[50],b[50],c[100]; int main()
{
int lena = 0, lenb = 0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c)); gets(s);
for(int i = strlen(s)-1; i>=0; i--)
a[lena++] = s[i]-'0'; gets(s);
for(int i = strlen(s)-1; i>=0; i--)
b[lenb++] = s[i] - '0'; for(int i = 0; i<50; i++)
{
int last = 0;
for(int j = 0; j<50; j++)
{
c[i+j] += a[i]*b[j];
c[i+j] += last;
last = c[i+j]/10;
c[i+j] = c[i+j]%10;
}
} int t = 99;
while(!c[t]) t--;
while(t>=0) printf("%d",c[t--]);
putchar('\n'); return 0;
}

顺便附上高精度加法的函数:

//高精度加法
void highplus(char a[],char b[],char c[])//调用前必须memset
{//将a+b存到c中,直接输出,但c是字符型,要整形则简修改即可
char ch;
int la = strlen(a),lb = strlen(b);
for(int i = 0;i<=(la-1)/2;i++)//将a和b位数倒转,以便逐位相加;同时-‘0’转成整形
{
ch = a[i]-'0';
a[i] = a[la-1-i]-'0';
a[la-1-i] = ch;
}
for(int i = 0;i<=(lb-1)/2;i++)
{
ch = b[i]-'0';
b[i] = b[lb-1-i]-'0';
b[lb-1-i] = ch;
} for(int i = 0;i<100;i++)//这里的100根据调用函数而修改
{ //逐位计算,依照加法竖式
c[i] += b[i]+a[i];
c[i+1] += c[i]/10;
c[i] %= 10;
} int i = 99;//若精度不同记得修改
while(!c[i]) i--;//跳过无用的0;
for(int j = 0;j<=i/2;j++)//将c再换成字符型,并再倒叙,使其成为正常数
{ //记住要经过中间数,否则中间一个将没有转成字符型,所以用<=(len-1)/2
ch = c[j]+'0';
c[j] = c[i-j]+'0';
c[i-j] = ch;
}
}

POJ2389 —— 高精度乘法的更多相关文章

  1. [vijos P1040] 高精度乘法

    如果这次noip没考好,完全是因为从7月29日之后就没有再写过程序了.说起来,真是一个泪流满面的事实… 那这样一个弱智题练手恢复代码能力,竟然还花了我两个晚上(当然不是两整个晚上…) 第一天TLE了, ...

  2. 【PKU1001】Exponentiation(高精度乘法)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 145642   Accepted: 35529 ...

  3. hdu 1042 N!(高精度乘法 + 缩进)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...

  4. hdu 1042 N!(高精度乘法)

    Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in ...

  5. Vijos 1040 高精度乘法

    描述 高精度乘法 输入:两行,每行表示一个非负整数(不超过10000位) 输出:两数的乘积. 样例1 样例输入1 99 101 样例输出1 9999 题解 这道题和之前的Vijos 1010 清帝之惑 ...

  6. 【POJ 1001】Exponentiation (高精度乘法+快速幂)

    BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...

  7. [leetcode]43. Multiply Strings高精度乘法

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and ...

  8. H. GSS and Simple Math Problem 高精度乘法模板

    链接:https://www.nowcoder.com/acm/contest/104/G来源:牛客网 题目描述 Given n positive integers , your task is to ...

  9. 高精度乘法--C++

    高精度乘法--C++ 模仿竖式乘法,在第一步计算的时候将进位保留,第一步计算完再处理进位.(见代码注释) 若要处理正负情况,可在数据输入后加以判断,处理比较简单. 小数计算也可参照该方法,不过对齐方式 ...

随机推荐

  1. 布斯(Steve Jobs)在斯坦福大学的演讲稿,中英文对照版

    2005年6月14日,苹果CEO史蒂夫·乔布斯(Steve Jobs)在他的母校斯坦福大学的毕业典礼发表了著名的演讲,关于这段演讲,你会看到N多人的推荐(比如同样喜欢在大学演讲的李开复先生).此前曾经 ...

  2. eclipse不会自动编译的问题解决

    注意:非必要的时候,重新下载eclipse安装是最有效的解决方法. 以下为尝试的步骤: 1.看看project->Build Automatically有没有勾上?如果没有,勾上以后,clean ...

  3. SQL Server 2008 镜像的监控 - Joe.TJ -

    http://www.cnblogs.com/Joe-T/archive/2012/09/06/2673237.html

  4. OpenLayers3 动画

    参考文章 openlayers3中三种动画实现

  5. Android 你应该注意的开发规范

    本文由Blankj投稿. Blankjd的博客地址: http://www.jianshu.com/u/46702d5c6978 为了利于项目维护以及规范开发,促进成员之间Code Review的效率 ...

  6. Zen of Python(Python的19条哲学)

    The Zen of Python Beautiful is better than ugly. Explicit is better than implicit. Simple is better ...

  7. UVA571 - Jugs(数论)

    UVA571 - Jugs(数论) 题目链接 题目大意:给你A和B的水杯.给你三种操作:fill X:把X杯里面加满水.empty X:把X杯中的水清空.pour X Y 把X的水倒入Y中直到一方满或 ...

  8. cucumber 使用资料

    1.cucumber reporting github:https://github.com/damianszczepanik/cucumber-reporting 配置:详细参考上述地址描述 a.添 ...

  9. 百科知识 epub文件如何打开

    .epub 简介 EPub是一个自由的开放标准,属于一种可以"自动重新编排"的内容:也就是文字内容可以根据阅读设备的特性,以最适于阅读的方式显示.EPub档案内部使用了XHTML或 ...

  10. PHP如何学习?

    PHP 的学习,可以归纳为三个类型:      语言的基础语法学习,这些是 ifelse, while, switch, class, function, trait 等:  内置函数/类学习,这 ...