sdut2613(This is an A+B Problem)大数加法(乘法)
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
char a[1010],b[1010];
int ta[1010],tb[1010];
int main()
{
int l2,l1,l;
while(scanf("%s%s",a,b)!=EOF)
{
memset(ta,0,sizeof(ta));
memset(tb,0,sizeof(tb));
l1=strlen(a);
l2=strlen(b);
if(l1<l2) l=l2;
else l=l1;
for(int i=0;i<l;i++)
{
if(l1-1>=0)
{
ta[i]=a[l1-1]-'0';
l1--;
}
else ta[i]=0;
if(l2-1>=0)
{
tb[i]=b[l2-1]-'0';
l2--;
}
else tb[i]=0;
}
int t;
for(int i=0;i<l;i++)
{
t=ta[i]+tb[i];
if(t>=10)
{
ta[i]=t-10;
ta[i+1]++;
}
else ta[i]=t;
}
int flag=0;
for(int i=l;i>=0;i--)
{
if(flag||ta[i])
{
flag=1;
printf("%d",ta[i]);
}
}
if(!flag) printf("0");//用于解决只有0相加的状况
printf("\n");
}
return 0;
}
Integer Inquiry
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; int main()
{
int l1;
char a[];
int b[];
memset(b,,sizeof(b));
while(scanf("%s",a)!=EOF)
{
if(a[]=='') break;
l1=strlen(a);
int j=;
for(int i=l1-; i>=; i--)
{
b[j]=b[j]+a[i]-'';
j++;
}
}
int t;
for(int i=; i<; i++)
{
t=b[i];
if(b[i]>)
{
b[i]=t%;
b[i+]=b[i+]+t/;
}
else b[i]=t;
}
int flag=;
for(int i=-; i>=; i--)
{
if (flag || b[i])
{
flag = ;
printf("%d",b[i]);
}
}
if (!flag) printf("");
printf("\n");
return ;
}
Product
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
char str1[],str2[];
int d[],f[],c[];
int l1,l2,l,w,e;
void init()
{
memset(c,,sizeof(c));
memset(d,,sizeof(d));
memset(f,,sizeof(f));
}
int main()
{
while(scanf("%s",str1)!=EOF)
{
init();
scanf("%s",str2);
l1=strlen(str1);
l2=strlen(str2);
l=max(l1,l2);
w=l1;
e=l2;
for(int i=; i<l; i++)
{
if(l1->=)
{
d[i]=str1[l1-]-'';
l1--;
}
else d[i]=;
if(l2->=)
{
f[i]=str2[l2-]-'';
l2--;
}
else f[i]=;
}
for(int i=; i<w; i++)
{
for(int j=; j<e; j++)
{
c[i+j]=c[i+j]+d[i]*f[j];
}
}
for(int i=; i<; i++)
{
if(c[i]>=)
{
c[i+]+=c[i]/;
c[i]=c[i]%;
}
}
int flag=;
for(int i=; i>=; i--)
{
if(flag||c[i])
{
flag=;
printf("%d",c[i]);
}
}
if(flag==) printf("");
printf("\n"); }
return ;
}
sdut2613(This is an A+B Problem)大数加法(乘法)的更多相关文章
- vector、string实现大数加法乘法
理解 vector 是一个容器,是一个数据集,里边装了很多个元素.与数组最大的不同是 vector 可以动态增长. 用 vector 实现大数运算的关键是,以 string 的方式读入一个大数,然后将 ...
- [acm 1001] c++ 大数加法 乘法 幂
北大的ACM 1001 poj.org/problem?id=1001 代码纯手动编写 - - #include <iostream> #include <cstdio> #i ...
- A + B Problem II(大数加法)
http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Other ...
- A+B and A*B problem 大数相加 相乘 模拟
A+B and A*B problem 大数相加 相乘 模拟 题意 给你两个数a和b,这两个数很大,然后输出这两个数相加的和,相乘的积. 解题思路 模拟,但是还是搜了搜代码实现,发现这个大佬写的是真的 ...
- A + B Problem II 大数加法
题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- hdu 1002 A + B Problem II【大数加法】
题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...
- 大数加法(A + B Problem Plus)问题
解题思路 两个⼤数可以⽤数组来逐位保存,然后在数组中逐位进⾏相加,再判断该位相加后是否需要进位.为了⽅便计算,可以把数字的低位放到数组的前面,高位放在后面. 样例输入 3 18 22 56 744 5 ...
- 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)
题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...
随机推荐
- EGit系列第二篇——关联远程仓库
网上也有很多代码托管网站支持git,像最出名的GitHub,还有国内支持私有项目的OSC开源中国和CSDN等... 首先得注册个帐号,然后才可以创建仓库 一般都会带一个ReadMe.md,你可以勾选也 ...
- 【宝塔】 安装扩展Memcached redis 教程
宝塔官网: www.bt.cn 开始安装 1 进入ssh 输入以下指令, wget -O ext.sh http://125.88.182.172:5880/ext/ext.sh && ...
- Android 屏幕适配:最全面的解决方案
转自:https://www.jianshu.com/p/ec5a1a30694b 前言 Android的屏幕适配一直以来都在折磨着我们Android开发者,本文将结合: Google的官方权威适配文 ...
- 题目1448:Legal or Not(有向无环图判断——拓扑排序问题)
题目链接:http://ac.jobdu.com/problem.php?pid=1448 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十一:PS/2模块⑤ — 扩展鼠标
实验十一:PS/2模块⑤ — 扩展鼠标 当普通鼠标即三键鼠标再也无法满足需求的时候,扩展鼠标即滚轮鼠标就诞生了,然而实验十一的实验目的就是实现滚轮鼠标的驱动.不过,进入整体之前,先让我们来了解一下鼠标 ...
- Gnome排序
Gnome排序(地精排序),起初由Hamid Sarbazi-Azad 于2000年提出,并被称为stupid排序,后来被Dick Grune描述并命名为“地精排序”,作为一个排序算法,和插入排序类似 ...
- IIS7配置伪静态把后缀名映射为html方案
1.在IIS新建站点.[创建的时候不用去选择版本和模式,默认即可] 2.选中站点,切换到功能试图,找到“处理程序映射",双击之后,在打开窗口右侧的操作栏目下做如下设置: 1)右边" ...
- [APP] Android 开发笔记 001-环境搭建与命令行创建项目
1. 安装JDK,SDK JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html Android SDK http ...
- nodejs事件的监听与事件的触发
nodejs事件(Events) 一.事件机制的实现 Node.js中大部分的模块,都继承自Event模块(http://nodejs.org/docs/latest/api/events.html ...
- iOS - 使用WKWebView时OC调JS的user-select属性控制用户操作
// 页面加载完成之后调用 - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigatio ...