题目链接:http://poj.org/problem?id=2389

题目意思:就是大整数乘法。

  题目中说每个整数不超过 40 位,是错的!!!要开大点,这里我开到100.

  其实大整数乘法还是第一次写 = =.......大整数加法写得比较多。百练也有一条是大整数乘法,链接如下:http://bailian.openjudge.cn/practice/2980/

  一步一步模拟即可,代码就是按这个来写的。

  以 835 * 49 为例(亲爱的读者,允许我截图吧)

简直就是神奇呀~~~~~

   

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
char ca[maxn], cb[maxn];
int ia[maxn], ib[maxn];
int res[*maxn+]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
while (scanf("%s%s", ca, cb) != EOF)
{
int l1 = strlen(ca);
for (int i = ; i < l1; i++)
ia[l1-i-] = ca[i] - '';
int l2 = strlen(cb);
for (int i = ; i < l2; i++)
ib[l2-i-] = cb[i] - '';
memset(res, , sizeof(res));
for (int i = ; i < l1; i++)
{
for (int j = ; j < l2; j++)
res[i+j] += ia[i] * ib[j];
}
// 处理进位问题
for (int i = ; i < l1+l2; i++)
{
if (res[i] >= )
{
res[i+] += res[i] / ;
res[i] %= ;
}
}
bool flag = false;
for (int i = maxn; i >= ; i--)
{
if (flag)
printf("%d", res[i]);
else if (res[i])
{
printf("%d", res[i]);
flag = true;
}
}
if (!flag)
printf("");
printf("\n");
}
return ;
}

  

poj 2389.Bull Math 解题报告的更多相关文章

  1. POJ 2389 Bull Math(水~Java -大数相乘)

    题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...

  2. Poj OpenJudge 百练 2389 Bull Math

    1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...

  3. Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)

     http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...

  4. POJ 3126 Prime Path 解题报告(BFS & 双向BFS)

    题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...

  5. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

  6. 【原创】poj ----- 2376 Cleaning Shifts 解题报告

    题目地址: http://poj.org/problem?id=2376 题目内容: Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K ...

  7. 【原创】poj ----- 1611 The Suspects 解题报告

    题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS   Memory Limit: 20000K To ...

  8. 【原创】poj ----- 2524 Ubiquitous Religions 解题报告

    题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 6 ...

  9. [POJ 1002] 487-3279 C++解题报告

        487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 228365   Accepted: 39826 D ...

随机推荐

  1. Markdown 写作工具选择

    Markdown 写作工具选择 候选产品 参考了少数派网站 markdown 写作工具2015年度盘点 http://sspai.com/32483, Windows 下 Markdown 的编辑工具 ...

  2. zepto-selector.js简单分析

    zepto 的selector模块是对jquery扩充选择器(jquery-selector-extensions)的部分实现.比如这样的选择方法:$('div:first') 和 el.is(':v ...

  3. 【C语言入门教程】4.4 指针 与 指针变量

    在程序中声明变量后,编译器就会为该变量分配相应的内存单元.也就是说,每个变量在内存会有固定的位置,有具体的地址.由于变量的数据类型不同,它所占的内存单元数也不相同.如下列声明了一些变量和数组. int ...

  4. HTML5 video 视频标签 常用属性

    最近在做手机端的 h5 页面的视频直播功能,用到了 Video 标签.其常用的属性有以下几个: src.poster.preload.autoplay.loop.controls.width.heig ...

  5. Mac Pro 安装 Sublime Text 2.0.2,个性化设置,主题 和 插件 收藏

    1.到官网下载安装包 http://www.sublimetext.com/2 2.附注册码一枚 ----- BEGIN LICENSE ----- Andrew Weber Single User ...

  6. Java网络编程学习

    服务器是指提供信息的计算机或程序,客户机是指请求信息的计算机或程序,而网络用于连接服务器与客户机,实现两者相互通信.但有时在某个网络中很难将服务器与客户机区分开.我们通常所说的“局域网”(Local ...

  7. window.location.href 和 window.location.replace 的区别

    window.location.href  和  window.location.replace 的区别 1.window.location.href=“url”:改变url地址: 2.window. ...

  8. MySQL中快速复制数据表方法汇总

    本文将着重介绍两个MySQL命令的组合,它将以原有数据表为基础,创建相同结构和数据的新数据表. 这可以帮助你在开发过程中快速的复制表格作为测试数据,而不必冒险直接操作正在运行 的数据表. 示例如下: ...

  9. NSTimer用法,暂停,继续,初始化

    NSTimer用法,暂停,继续,初始化 转载:http://blog.csdn.net/zhuzhihai1988/article/details/7742881 NSTimer的使用方法 1.初始化 ...

  10. SSH-Struts第一弹:ActionSupport类

    Action继承了com.opensymphony.xwork2.ActionSupport. package com.candy.login; import com.opensymphony.xwo ...