Problem A+B(Big Integer)
/*========================================================================
Problem A+B(Big Integer)
Time Limit:1000MS Memory Limit:65536KB
Total Submit:3205 Accepted:922
Description
Give two positive integer A and B,calucate A+B.
Notice that A,B is no more than 500 digits.
Input
The test case contain several lines.Each line contains two positive integer A and B.
Output
For each input line,output a line contain A+B
Sample Input
2 3
1231231231823192 123123123123123
1000000000000000 1
Sample Output
5
1354354354946315
1000000000000001
Source
EOJ
==========================================================================*/
http://202.120.80.191/problem.php?problemid=1001
#include<stdio.h>
#include<string.h>
void sum(char a[],char b[],char c[]);//c=a+b
void swap(char a[]);
int main()
{
char a[],b[],c[];
freopen("5.in","r",stdin);
while(scanf("%s%s",a,b)!=EOF)//while(cin>>a>>b)
{
sum(a,b,c);
printf("%s\n",c);
}
return ;
}
void sum(char a[],char b[],char c[])//c=a+b
{
int i,lenA,lenB,min,max;
int carry=,t;
lenA=strlen(a);
lenB=strlen(b);
swap(a);
swap(b);
if(lenA>lenB)
{
max=lenA;
min=lenB;
}
else
{
max=lenB;
min=lenA;
}
for(i=;i<min;i++)
{
t=(a[i]-'')+(b[i]-'')+carry;
c[i]=t%+'';
carry=t/;
}
if(lenA>lenB)
{
for(i=min;i<max;i++)
{
t=(a[i]-'')+carry;
c[i]=t%+'';
carry=t/;
}
}
else
{
for(i=min;i<max;i++)
{
t=(b[i]-'')+carry;
c[i]=t%+'';
carry=t/;
}
}
if(carry!=)
{
c[i]=carry+'';
i++;
}
c[i]='\0';
swap(c);
}
void swap(char a[])
{
int i,len=strlen(a),t=len/;
char ch;
for(i=;i<t;i++)
{
ch=a[i];
a[i]=a[len--i];
a[len--i]=ch;
}
}
Problem A+B(Big Integer)的更多相关文章
- Facebook interview problem:13. Roman to Integer
description: Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symb ...
- [LeetCode&Python] Problem 13. Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- leetcode解决问题的方法||Integer to Roman问题
problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...
- Longge's problem poj2480 欧拉函数,gcd
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6918 Accepted: 2234 ...
- Very Simple Problem
Very Simple Problem Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ2480 Longge's problem
题意 Language:Default Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1064 ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6383 Accepted: 2043 ...
- Longge's problem(欧拉函数应用)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
随机推荐
- 多个storyboard开发应用程序,封装.bundle和.a不用xib使用storyboard!!!
一,封装.bundle和.a使用xib的方式前面已经说过了,具体方式不再赘述,简单介绍于下: 静态库加.h bundle:删plist,改sdk,加xib 简称psx三步 引用库的项目,加.a .b ...
- HDU 4971 (最小割)
Problem A simple brute force problem (HDU 4971) 题目大意 有n个项目和m个问题,完成每个项目有对应收入,解决每个问题需要对应花费,给出每个项目需解决的问 ...
- hadoop权威指南 读书笔记
1 数据库和MapReduce对比 2 hadoop 包含的内容
- bind 方法实现
[要求]:实现 bind 方法 [实现]: // 简单方法 Function.prototype.bind = Function.prototpe.bind || function(context) ...
- Linux服务器使用命令操作MySQL插入数据乱码问题
服务器上使用MySQL命令方式进行插入数据时,很多时候会遇到插入数据乱码问题,导出一个sql执行文件,再倒入到unbutn中,结果出现乱码,折腾7-8分钟, 解决方式 在导出mysql sql执行文件 ...
- JAVA学习之Ecplise IDE 使用技巧(2)第二章:键盘小快手,代码辅助
上一篇:JAVA学习之Ecplise IDE 使用技巧(1)第一章:我的地盘我做主,工作空间 第二章:键盘小快手,代码辅助 内容包括: 第一:显示行号 如何设置行号:Ecplice菜单Windows& ...
- RelativeLayout相对布局
RelativeLayout相对布局常用属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_center ...
- html5实现饼图和线图-我们到底能走多远系列(34)
我们到底能走多远系列(34) 扯淡: 送给各位一段话: 人生是一个不断做加法的过程 从赤条条无牵无挂的来 到学会荣辱羞耻 礼仪规范 再到赚取世间的名声 财富 地位 ...
- 在WAS 中建立db2 dataSource
1: 安全性->JAAS配置->J2C认证数据: 新建-> 名称(随意起) 数据库用户名 密码.数据库密码 2:应用程序服务器?server1?Web容器?会话管理?分布式环境设置 ...
- taglib 自定义标签
自定义<%@ taglib prefix="cf" uri="http://training.bmcc.com.cn/tld/functions"%> ...