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 ...
随机推荐
- ios--NSCalendar NSDateComponents
原文: ios时间那点事--NSCalendar NSDateComponents http://my.oschina.net/yongbin45/blog/156181 目录[-] iOS时间那点事 ...
- Date and Time
The PHP date() function is used to format date and/or a time and formats as timestamp to a more read ...
- Unity3D ShaderLab 各向异性高光
Unity3D ShaderLab 各向异性高光 各向异性时一种模拟物体表面沟槽方向性的高光反射类型,它会修改或延伸垂直方向上的高光.当我们想模拟金属拉丝高光的时候,它非常适合.下面就一步一步实现. ...
- GOLANG 反射法则
译自[blog.golang.org/laws-of-reflection] 在计算机中, 反射是程序通过类型,检测到它自己的结构能力:是一种元编程程:也是一个具大的混淆点 在本文中,我们将通过解释反 ...
- Tranparent/cutout/diffuse
Shader "Tranparent/cutout/diffuse" { Properties { // _Color ("Main Color", Co ...
- Runtime 、 Block
1 使用Block方式,对学生对象进行排序. 1.1 问题 在iOS4.0+ 和Mac OS X 10.6+ 中添加了Block概念,以对C语言进行扩展.在Block中可以定义参数列表.返回类型,还可 ...
- C++学习笔记6:多文件编程
1.添加文件到工程中: 2.函数调用时需要前向声明;以下为实例: //add.cpp int add(int x, int y) { return (x + y); } //main.cpp #inc ...
- Day06_面向对象第一天
1.JAVA中的参数传递问题(掌握) 基本类型 形式参数的改变对实际参数没有影响 基本类型的实际参数和形式参数可以看作两个变量,这两个变量分别操作各自的数据,所以互不影响 引用类 ...
- dede的pagelist标签的listsize数字属性详解(借鉴)
dede的pagelist标签的listsize数字属性详解.见远seo经常用织梦搭建各种网站,有次发现列表页面的分页显示超过div的界限,也就是溢出了或者说是撑破了.后来经过研究发现是pagelis ...
- python xlrd和xlwtxlutils包的使用
安装xlrd读取模块 首先去官网或者pypi下载安装包,然后解压到任意目录 在dos下进入该目录,执行python setup.py install安装 验证成功进入python,执行import 包 ...