/*========================================================================
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. typedef的用法

    我最开始学习的是C++,而不是C语言.虽说C++涵盖了C,但是C++的语法更加方便,比如输入输出……但是为了与C兼容,常常需要保留C语言的用法,这就比较烦人了,因为我们都希望有一个固定的语法. 首先让 ...

  2. Python OpenCV —— Border

    关于border的部分,边缘处理. # -*- coding: utf-8 -*- """ Created on Wed Sep 28 00:58:51 2016 @au ...

  3. PHP面向对象中常用的关键字和魔术方法

    PHP面向对象中常用的关键字 final        1.final不能修饰成员属性(类中常量不是用这个关键字)        2.final只能修饰类和方法 作用:            使用fi ...

  4. linux命令:mkdir

    1.介绍: mkdir用来创建目录,要求创建目录的用户在当前目录具有写的权限. 2.命令格式: mkdir [选项] 目录 3.命令参数 -m, --mode=模式,设定权限<模式> (类 ...

  5. Squid Proxy Server 3.1

    Improve the performance of your network using the caching and access control capabilitiess of squid. ...

  6. Cryptography加密和解密

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Se ...

  7. unable to open sync connection

    有些时候,在你向连接好的Android机器中按照程序时会遭遇失败,logcat提示“unable to open sync connection”. 一般情况下,重启手机几乎肯定可以解决这个问题. 如 ...

  8. jq 全选/取消效果

    //全选框$('#btnbutton').live('click',function(){ var data = $(this).attr('data'); if(data=='on'){ $(&qu ...

  9. 安装arbotix simulator仿真环境--9

    原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/  周学伟 安装之前:首先确保已经正常制作了ros工作空间并且安装了rbx1功能包: cd ~/catki ...

  10. 越狱Season 1-Episode 21: Go

    Season 1, Episode 21: Go -Michael: I need you to let me get us out of here. 我需要你帮我出去 -Patoshik: If y ...