描述

高精度乘法

输入:两行,每行表示一个非负整数(不超过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. H5水果机,一个网络版的lao hu ji

    该游戏为h5小游戏,纯属娱乐,技术探讨,相关技术在文章结尾,欢迎探讨交流 花了几天时间开发了这款水果lao hu ji,更新了几个版本,还有不足的地方,由于时间有限暂时没有继续更新新版本 未完成的功能 ...

  2. liunx命令1

    单词整理 terminal:终端 network-scripts:网络脚本 passwd:密码文件 nologin:禁止登陆 shutdown:关机 reboot:重启 poweroff:关机 gre ...

  3. 关于c#邮件发送的简单例子

    这里所说的发送邮件,以发送qq邮件为例. 首先我们先要在自己的邮箱配置好如下选项:

  4. prop()、attr()和data()

    设置元素属性,用attr()还是prop()? 对于取值为true /false的属性,如 checked/selected/readonly或者disabled,使用prop(),其他属性使用 at ...

  5. OpenCV探索之路(十三):详解掩膜mask

    在OpenCV中我们经常会遇到一个名字:Mask(掩膜).很多函数都使用到它,那么这个Mask到底什么呢? 一开始我接触到Mask这个东西时,我还真是一头雾水啊,也对无法理解Mask到底有什么用.经过 ...

  6. 第十五章(附)分布式缓存-Memcached

    一.概念 Memcached是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能. 二.适用场合 1.分布式应用.由于 ...

  7. Tomcat 安装与配置

    1. 将压缩文件“apache-tomcat-7.0.62.zip ”上传到linux系统目录:/home/下 2. 进入目录 cd /home/ 解压文件,执行如下命令:unzip apache-t ...

  8. python利用selenium和safari浏览器驱动实现新浪微博自动点赞 Demo

    import time from selenium import webdriver browser = webdriver.Safari() browser.get('http://weibo.co ...

  9. unity3D:游戏分解之角色移动和相机跟随

          游戏中,我们经常会有这样的操作,点击场景中某个位置,角色自动移动到那个位置,同时角色一直是朝向那个位置移动的,而且相机也会一直跟着角色移动.有些游戏,鼠标滑动屏幕,相机就会围绕角色旋转. ...

  10. python基础操作_方法(函数)

    #函数,方法#普通方法def hello(): print('hello')hello()#带形参的方法def hello1(name): print('hello%s'%name)hello1('布 ...