描述

高精度乘法

输入:两行,每行表示一个非负整数(不超过10000位)

输出:两数的乘积。

样例1

样例输入1

99

101

样例输出1

9999

题解

这道题和之前的Vijos 1010 清帝之惑之乾隆一样是求高精度乘法的题,不同之处是这次是两个大数乘法,之前是一个大数和一个整数范围内的数进行乘法,所以数据的保存方式和处理方式稍微有些区别。具体见代码:)

代码:

#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 20020;
char s[maxn], t[maxn], res[maxn], tmp[maxn];
int lenS, lenT;
void preSolve()
{
memset(tmp, 0, sizeof(tmp));
memset(res, 0, sizeof(res));
lenS = strlen(s);
lenT = strlen(t);
// strrev(s);
// strrev(t);
for (int i = 0; i < lenS/2; i ++)
{
char p = s[i];
s[i] = s[lenS-1-i];
s[lenS-1-i] = p;
}
for (int i = 0; i < lenT/2; i ++)
{
char p = t[i];
t[i] = t[lenT-1-i];
t[lenT-1-i] = p;
}
for (int i = 0; i < lenS; i ++)
s[i] -= '0';
for (int i = 0; i < lenT; i ++)
t[i] -= '0';
}
void solve()
{
for (int i = 0; i < lenT; i ++)
{
int a = t[i];
int c = 0;
for (int j = 0; j < lenS + 1; j ++)
{
c += t[i] * s[j];
tmp[j] = c % 10;
c /= 10;
}
c = 0;
for (int j = 0; j < lenS + 1; j ++)
{
c += tmp[j] + res[i+j];
res[i+j] = c % 10;
c /= 10;
}
}
int i = maxn-1;
for (;res[i] == 0 && i > 0; i --);
for (;i >= 0; i--)
printf("%d", res[i]);
puts("");
}
int main()
{
scanf("%s%s", s, t);
preSolve();
solve();
return 0;
}

Vijos 1040 高精度乘法的更多相关文章

  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. 【POJ 1001】Exponentiation (高精度乘法+快速幂)

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

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

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

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

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

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

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

  9. C语言高精度乘法

    #include <stdio.h> void highPrecision (int N ); ] = {, }, length = ; //开辟一个大的数组,全局变量length记录长度 ...

随机推荐

  1. ke

    #include <stdio.h> #include <stdlib.h> // For rand() and srand() #include <time.h> ...

  2. 0Raspi开启root权限并登录使用

    sudo passwd root sudo passwd --unlock root su root  切换回用 su pi   开始登陆选择root preferences>raspberry ...

  3. php implode()函数详解

    php implode()函数的作用? php 中implode() 函数是返回一个由数组元素组合成的字符串,它与php explode()函数的作用是相反的,php explode() 函数是:使用 ...

  4. 卸载XCode插件的方法

    1.Finder--前往---前往文件夹--输入~/Library/Developer/Xcode/Plug-ins 2.删除要卸载的插件即可.

  5. 从矩阵的定义开始谈OpenGL矩阵变换

    前言 最近自己想用C语言写一个Minecraft clone(GitHub链接:http://github.com/CharlesDong/m3c/),因为是现代OpenGL,又是C语言,GLM用不了 ...

  6. xampp教程(一):xampp下载,安装,配置,运行PHP的web项目

    本来没有想着弄PHP,但是有同学叫我帮忙启动一下一个PHP写的后台.着实需要去学习一下. 想着安装xampp软件,一个集合了多个服务器,多个数据库,多个后台语言的管理软件. 一.xampp下载 二.安 ...

  7. 一天搞定CSS: 浮动(float)及文档流--10

    浮动(float),一个我们即爱又恨的属性.爱,因为通过浮动,我们能很方便地布局: 恨,浮动之后遗留下来太多的问题需要解决,特别是IE6-7(以下无特殊说明均指 windows 平台的 IE浏览器). ...

  8. JS闭包,以及适用场景

    闭包的定义 不用解释了,网上到处都是.简单的说:一个定义在函数内部的函数与包含它的外部函数构成了闭包,内部函数可以访问外部函数的变量,这些变量将一直保存在内存中,直到无法再引用这个内部函数 举个例子: ...

  9. MVC4加载zTree树小控件

    前言: 第一次学习使用MVC框架,找了个练手项目,加载zTree树小控件.下面我就一步步说明我这次练手的经历以记录.如果有什么错误,希望各位大神帮忙指正,谢谢. 第一步: 利用VS2010新建一个MV ...

  10. js for循环 等腰三角形demo

    <script> for(var i=1;i<10;i++){ for(var j=1;j<10-i;j++){document.write(" ")} f ...