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 ...
随机推荐
- 基于VLAN的二三层转发
[章节内容]1 MAC地址2 冲突域和广播域3 集线器.交换机.路由器 3.1 集线器 3.2 网桥和交换机 3.3 路由器4 VLAN 4.1 VLAN帧格式 4.1.1 ...
- linux c++环境
set expandtab set autoindent set smartindent
- WP8.1学习系列(第九章)——透视Pivot开发指南
Windows Phone 8 的 Pivot 控件 2014/6/18 适用于:Windows Phone 8 和 Windows Phone Silverlight 8.1 | Windows P ...
- WP8.1学习系列(第七章)——应用选项卡Pivot交互UX
“应用选项卡”模式用于用户经常在中间导航的多个 UI 页面.如果你的应用基于单个主题(例如,电影.棒球等),该模式尤其有用.每页都将为用户显示与该应用呈现的整体数据相关的一些内容.“应用选项卡”模式可 ...
- 【2014年12月6日】HR交流会
今天的交流会感觉还是不错,体会到了一些东西,把它记下来. 想到什么写什么,可能没什么条理. 1.先选行业,再选职业,再选公司 根据自己的兴趣以及个人特长,能力等方面,需要定一个大概的方向,然后根据方向 ...
- chorme 浏览器记住密码后input黄色背景处理
使用chrome浏览器选择记住密码的账号,输入框会自动加上黄色的背景,有些设计输入框是透明背景的,需要去除掉这个黄色的背景: 方法1:阴影覆盖 input:-webkit-autofill { -we ...
- javascript 闭包学习
闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域 ...
- 删除个别主机的Know_hosts文件信息
方法一: rm -rf ~/.ssh/known_hosts 缺点:把其他正确的公钥信息也删除,下次链接要全部重新经过认证 方法二: vi ~/.ssh/known_hosts 删除对应ip的相关rs ...
- Druid的Segment Balance及其代价计算函数分析
Balance $Cost(X, Y) $ $$ J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \Gamma (m + \alpha + 1)} { ...
- Docker添加镜像加速器
Docker默认pull连接镜像为国外镜像,速度较慢,注册阿里云可以生成一个镜像加速器 登录阿里云 https://cr.console.aliyun.com获取私有加速地址 修改配置文件/etc/d ...