#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. php API接口入门

    1.简述: api接口开发,其实和平时开发逻辑差不多:但是也有略微差异: 平时使用mvc开发网站的思路一般是都 由控制器 去 调用模型,模型返回数据,再由控制器把数据放到视图中,展现给用户: api开 ...

  2. laravel调用sql server存储过程并取得ReturnValue

    alter proc [dbo].[aaa](    @AgencyID int,--代理商ID    @AdminID int --结算操作人ID(管理员ID))asbegin    select ...

  3. jquery validate 多种使用方式

    前言:jQuery.validator是一款非常不错的表单验证插件,验证方式非常简单方便,它还对HTML5做了兼容处理,了解了验证规则,就基本掌握了它的使用,下面就让我一一道来 jQuery.vali ...

  4. Apache 的mod_auth_cas模块的介绍和使用

    apache的mod_auth_cas模块是一个集成到apache中的cas客户端,一般是配合Apache的反向代理来使用,对某个url的请求先经过apache,apache会判断是否经过cas认证, ...

  5. 剑指offer题目记录

    1.如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char* pData = NULL); CMyStri ...

  6. Jmeter TCP取样器配置及发送图解

    最近在通过Jmeter测试TCP发送请求时,遇到相关问题,现记录 查看管方文档,TCP发送有三种启用方式: TCPClientImpl:文本数据,默认为这种 BinaryTCPClientImpl:传 ...

  7. jdbc(1)(三)DBCP、C3P0、Proxool 、 BoneCP开源连接池的简介

     简介          使用评价  项目主页  DBCP DBCP是一个依赖Jakarta commons-pool对象池机制的数据库连接池.DBCP可以直接的在应用程序用使用 可以设置最大和最小连 ...

  8. python添加Windows环境变量

    1.cmd中添加方式 SET PATH=%PATH%;c:\Program Files (x86)\Wireshark 注:如上代码添加c:\Program Files (x86)\Wireshark ...

  9. Java 多线程 线程的五种状态,线程 Sleep, Wait, notify, notifyAll

    一.先来看看Thread类里面都有哪几种状态,在Thread.class中可以找到这个枚举,它定义了线程的相关状态: public enum State { NEW, RUNNABLE, BLOCKE ...

  10. powerdesigner唯一约束设置

    双击unique_pos_code