/*========================================================================
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)的更多相关文章

  1. 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 ...

  2. [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 ...

  3. leetcode解决问题的方法||Integer to Roman问题

    problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...

  4. Longge's problem poj2480 欧拉函数,gcd

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6918   Accepted: 2234 ...

  5. Very Simple Problem

    Very Simple Problem Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  6. POJ2480 Longge's problem

    题意 Language:Default Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1064 ...

  7. poj 2480 Longge's problem 欧拉函数+素数打表

    Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathem ...

  8. 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 ...

  9. Longge's problem(欧拉函数应用)

    Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...

随机推荐

  1. UITouch的用法

    UITouch一般无法直接获取,是通过UIView的touchesBegan等函数获得. //这四个方法是UIResponder中得方法 // Generally, all responders wh ...

  2. Java容器类接口:Iterator,Collection,Map

    Iterator Iterator被称为迭代器,是一个对象,它的工作是遍历并选择序列中的对象,可以实现以下一些操作: 使用方法iterator()要求容器返回一个Iterator,Iterator将返 ...

  3. JQuery源码分析(三)

    jQuery中ready与load事件 jQuery有3种针对文档加载的方法 $(document).ready(function() { // ...代码... }) //document read ...

  4. Mac快捷键 Xcode快捷键

    Mac OSX 快捷键&命令行   一.Mac OSX 快捷键 ctrl+shift                                    快速放大dock的图标会暂时放大,而 ...

  5. 如何配置magento免运费商品方法

    作为magento电商来说,免运费是一种常见的促销手段,要让产品成为免运费对magento来说并不难,后台操作即可完成. 首先,我们要建立一个新的产品属性. catalog->attribute ...

  6. LRU

    rsms/js-lru LRU缓存介绍与实现 (Java) 使用场景 缓存计算结果

  7. IE下背景图片 不显示问题

    转自:http://www.jb51.net/css/119341.html 在chrome,FF里调试完后,忽然想起ie来,放到Ie里其它还好了,但是有个背景图片显示不出来,具体的写法如下,有类似情 ...

  8. Linux发展史

    简述 Linux是一套自由加开放源代码的类Unix操作系统,诞生于1991年10月5日(第一次正式向外公布),由芬兰学生Linus Torvalds和后来陆续加入的众多爱好者共同开发完成. Linux ...

  9. jquery 平滑滚动页面到某个锚点

    $(document).ready(function() {         $("a.topLink").click(function() {                 $ ...

  10. javascript 字符串方法名调用

    项目中有时候需要通过字符串传递方法名称,供页面调用 var ParameterDefaultCallMethod = Request("ParameterDefaultCallMethod& ...