#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)大数加法(乘法)的更多相关文章

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

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

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

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

  3. A + B Problem II(大数加法)

    http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Other ...

  4. A+B and A*B problem 大数相加 相乘 模拟

    A+B and A*B problem 大数相加 相乘 模拟 题意 给你两个数a和b,这两个数很大,然后输出这两个数相加的和,相乘的积. 解题思路 模拟,但是还是搜了搜代码实现,发现这个大佬写的是真的 ...

  5. A + B Problem II 大数加法

    题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...

  6. 大数加法~HDU 1002 A + B Problem II

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...

  7. hdu 1002 A + B Problem II【大数加法】

    题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...

  8. 大数加法(A + B Problem Plus)问题

    解题思路 两个⼤数可以⽤数组来逐位保存,然后在数组中逐位进⾏相加,再判断该位相加后是否需要进位.为了⽅便计算,可以把数字的低位放到数组的前面,高位放在后面. 样例输入 3 18 22 56 744 5 ...

  9. 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)

    题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...

随机推荐

  1. 【truffle】Error: `truffle init` no longer accepts a project template name as an argument.

    下载范例工程时候.使用命令报错 truffle init webpack 错误如下: Error: `truffle init` no longer accepts a project templat ...

  2. 分布式实时日志系统(二) 环境搭建之 flume 集群搭建/flume ng资料

    最近公司业务数据量越来越大,以前的基于消息队列的日志系统越来越难以满足目前的业务量,表现为消息积压,日志延迟,日志存储日期过短,所以,我们开始着手要重新设计这块,业界已经有了比较成熟的流程,即基于流式 ...

  3. 原生js--兼容获取窗口滚动条位置和窗口大小的方法

    各个浏览器对获取获取窗口滚动条位置和窗口大小没有提供统一的API,以下是对其封装,解决兼容性问题 /** * 获取浏览器视口的大小(显示文档的部分) *  */function getViewPort ...

  4. 【BZOJ2310】ParkII 插头DP

    [BZOJ2310]ParkII Description Hnoi2007-Day1有一道题目 Park:给你一个 m * n 的矩阵,每个矩阵内有个权值V(i,j) (可能为负数),要求找一条回路, ...

  5. 使用curl进行s3服务操作

    最近使用curl对s3进行接口测试,本想写个总结文档,但没想到已有前辈写了,就直接搬过来做个记录吧,原文见: http://blog.csdn.net/ganggexiongqi/article/de ...

  6. UVM phase的用法研究【zz】

    原文地址:http://bbs.eetop.cn/viewthread.php?tid=383872&extra=&authorid=828160&page=1 我相信很多朋友 ...

  7. 持续集成之jenkins

    代码部署规划 安装jenkins yum -y install java-1.8.0cd /etc/yum.repos.d/wget http://pkg.jenkins.io/redhat/jenk ...

  8. os.path 模块

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  9. 0003python中的可变参数

    >>>def foo(x,y,z,*args,**kargs): print x print y print z print args print kargs >>> ...

  10. Linux执行Cron Job失败,在Shell sh下执行却能成功 - 环境变量?

    博客分类: Linux linuxcrontabpermissionetc/profile环境变量  一.我们常常碰到在shell下执行某个命令能够成功,比如执行一个java程序: java -jar ...