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 ...
随机推荐
- atomic和nonatomic的区别
1.使用atomic进行修饰的属性,在实现文件中不能重写setter方法和getter方法,不然在编译过程会发生报错. 1.使用nonatomic进行修饰的属性,在实现文件中可以重写setter方法和 ...
- 桟的min实现:O(1)时间复杂度
实现桟的push和pop操作,以及桟的min操作返回桟中的最小值,要求这三个操作的时间复杂度均为O(1). 在Java中可以使用LinkedList实现桟的各种操作,这里使用双向链表实现桟的push和 ...
- Java 集合深入理解(11):LinkedList
点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 今天心情鱼肚白,来学学 LinkedList 吧! 日常开发中,保存一组数据使用的最多的就是 ArrayList, 其次就 ...
- WCF之多个协定
多个协定”示例演示如何在一个服务上实现多个协定,以及如何配置终结点以便与实现的每个协定进行通信 1.服务端代码如下(服务实现了两个协定,增加了黄色所示代码): class Program { stat ...
- shell命令:删除当前.sh文件所在目录下的zip包,并且重新打包
filepath=$(cd ")"; pwd) packagePath="$filepath"/package zipPath="$filepath& ...
- android webview如何加载asset目录里的页面
在asset里的页面都可以这样获得 file:///android_asset/index.html
- python, itertools模块
通过itertools模块,可以用各种方式对数据进行循环操作 1, chain() from intertools import chain for i in chain([1,2,3], ('a', ...
- (实用篇)微信网页授权(OAuth2.0) PHP 源码简单实现
提要: 1. 建议对OAuth2.0协议做一个学习. 2. 微信官方文档和微信官网工具要得到充分利用. 比较简单,直接帖源代码了.其中"xxxxxxxxxx"部分,是需要依据自己环 ...
- UI学习笔记---第十二天UITabBarController
页签视图控制器-UITabBarController 自定义UITabBar block高级 一.UITabBarController 结构为三层:Tab bar controller v ...
- 2003服务器断开rdp后会自动注销。
开始-运行-gpedit.msc-计算机配置-管理模板-Windows Components-Terminal Services-Sessions-Set time limit for disconn ...