题目:POJ 2398

Bull Math
Time Limit: 1000MS   Memory Limit: 65536K
Total 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.

Input

* Lines 1..2: Each line contains a single decimal number.

Output

* Line 1: The exact product of the two input lines

Sample Input

11111111111111
1111111111

Sample Output

12345679011110987654321

Source

嘴笨,直接上代码。

#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;
}

  

大数的乘法(C++)的更多相关文章

  1. vector、string实现大数加法乘法

    理解 vector 是一个容器,是一个数据集,里边装了很多个元素.与数组最大的不同是 vector 可以动态增长. 用 vector 实现大数运算的关键是,以 string 的方式读入一个大数,然后将 ...

  2. sdut2613(This is an A+B Problem)大数加法(乘法)

    #include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>u ...

  3. [acm 1001] c++ 大数加法 乘法 幂

    北大的ACM 1001 poj.org/problem?id=1001 代码纯手动编写 - - #include <iostream> #include <cstdio> #i ...

  4. HDU——1042N!(大数阶乘乘法)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  5. 剑指offer编程题Java实现——面试题12相关题大数的加法、减法、乘法问题的实现

    用字符串或者数组表示大数是一种很简单有效的表示方式.在打印1到最大的n为数的问题上采用的是使用数组表示大数的方式.在相关题实现任意两个整数的加法.减法.乘法的实现中,采用字符串对大数进行表示,不过在具 ...

  6. ACM学习历程—51NOD1028 大数乘法V2(FFT)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...

  7. ZZNUOJ-2154:单身狗线下聚会【求N个数的最小公倍数,会超longlong,大数乘法,Java】

    2154: 单身狗线下聚会 题目描述 马上就到七夕节了,单身狗们决定聚一聚.但是它们沉迷B站上的lo娘,他们每沉迷 ai 单身狗时间(这是它们专业计时)后就会休息 单身狗时间.它们想找到一个时间正好他 ...

  8. Cut the Cake(大数相乘)

      MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly o ...

  9. hdu 1042 N!(大数的阶乘)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. ThinkPad_T430重装系统

    联想thinkpad T430为T系列的旗舰级产品,全新的ThinkPad T430将该系列坚固的机身.稳定高效的散热表现.超强的易用性.不俗的性能以及出色的操控感受等优点完美的继承下来,始终坚持把每 ...

  2. 实用的Bootstrap的扩展和插件集合

    bootstrap插件 http://www.missyuan.net/school/other_2014/other_16472.html http://www.oschina.net/news/5 ...

  3. 【原创】windows下搭建vue开发环境+IIS部署

    [原创]win10下搭建vue开发环境  如果要转发,请注明原作者和原产地,谢谢! 特别说明:下面任何命令都是在windows的命令行工具下进行输入,打开命令行工具的快捷方式如下图:     详细的安 ...

  4. javascrit2.0完全参考手册(第二版) 第2章第1节 基本定义

    在这里,我们介绍一些将要使用的编程语言术语.表2-1提供了精确定义的概念. Table 2-1: 编程语言的基本术语 名字 定义 例子 Token令牌 最小的不可分割的词汇的语言单位.一个连续的字符序 ...

  5. js正则验证之不能使用相同字符

    在我们的前端开发中,为了不让用户输入相同的密码字符以提高其安全性,我们会写一个js方法来实现这个功能.接下来,我就来实现这个方法,有其他好的解决办法,敬请留言,博主必定向其学习. function _ ...

  6. 关于html页面布局

    之前做的一个网站,结果今天这几天测试发现在19寸屏幕和手机屏幕上页面布局全乱了,今天刚刚改好,发现还是自己经验不足,做个小总结. 一.div布局要固定宽高 当div不设计长宽高而是自动由内部控件”撑“ ...

  7. cursor 手型样式

    cursor:hand 与 cursor:pointer 的效果是一样,都像手形光标.但用FireFox浏览时才注意到使用cursor:hand在FireFox里并被支持.cursor:hand :I ...

  8. 2016HUAS暑假集训训练2 L - Points on Cycle

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/L 这是一道很有意思的题,就是给定一个以原点为圆心的圆,然后给定 一个点  求最大三 ...

  9. Oracle数据库更新时间的SQL语句

    ---Oracle数据库更新时间字段数据时的sql语句---格式化时间插入update t_user u set u.name='pipi',u.modifytime=to_date('2015-10 ...

  10. BizTalk开发系列(二十八) MSMQ 适配器

    MSMQ(MicroSoft Message Queue,微软消息队列)是在多个不同的应用之间实现相互通信的一种异步传输模式,相互通信的应用可以分布于同一台机器上,也可以分布于相连的网络空间 中的任一 ...