HDOJ1002题A + B Problem II,2个大数相加
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is “Case #:”, # means the number of the test case. The second line is the an equation “A + B = Sum”, Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
2 1 2 112233445566778899 998877665544332211
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
#include < stdio.h>
#include < stdlib.h>
#include < string.h>
int main()
{
char a[1010],b[1010],c[1010];
int a1,b1,m,i,l,i1,j1,n1,m1,a2,b2,j=1,t1,t2,n,p=0;
scanf("%d",&n);
while(n--)
{
p=0;
scanf("%s",a);
scanf("%s",b);
printf("Case %d:\n",j++);
printf("%s + %s = ",a,b);
a1=strlen(a);
b1=strlen(b);
a2=a1;
b2=b1;
for(i=0; a1>=0||b1>=0; i++,a1--,b1--)
{
if(a1>=0&&b1>=0)
{
c[i]=a[a1]+b[b1]-'0'+p;
}
else if(a1>=0&&b1<0)
{
c[i]=a[a1]+p;
}
else if(a1<0&&b1>=0)
{
c[i]=b[b1]+p ;
}
p=0;
if(c[i]>'9')
{
c[i]=c[i]-10;
p=1;
}
}
if(p==1)
printf("%d",p);
t1=1;
t2=i-1;
n1=m1=0;
for(i1=0; i1
{
if(a[i1]=='0')
n1++;
}
for(j1=0 ; j1
{
if(b[j1]=='0')
m1++;
}
if(n1==a2&&m1==b2)
{
printf("0");
}
else
{
for(l= i-1 ; l>0; l--)
{
if(t2==l&&c[l]=='0'&&p!=1)
{
t2--;
continue;
}
printf("%c",c[l]);
}
}
if(n!=0)
printf("\n\n");
else
printf("\n");
}
return 0;
}
HDOJ1002题A + B Problem II,2个大数相加的更多相关文章
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- HDU 1002.A + B Problem II-数组模拟-大数相加
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1002 A + B Problem II(大正整数相加)
代码: #include<cstdio> #include<cstring> #define Min(a,b) ((a)<(b)?(a):(b)) using names ...
- hdu1002 A + B Problem II(大数题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- Week 1 # A A + B Problem II
原题描述: A - A + B Problem II I have a very simple problem for you. Given two integers A and B, your jo ...
- hduoj 1002 A + B Problem II
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目描述如下: A + B Problem II Time Limit: 2000/1000 M ...
- HDU 1023 Train Problem II (大数卡特兰数)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Train Problem II(卡特兰数 组合数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...
随机推荐
- Linked Server for SQL Server 2012(x64) to Oracle Database 12c(x64)
因为把两台数据库装了同一台机机器上,所以没有安装oracle Client的部分,Oracle部分使用netca创建的Net Service Name,使用tnsping以及登入方式的确认用户权限的以 ...
- WebService学习笔记
WebService有什么用? 入门之前先简单介绍下WCF.在用WebService做开发时,很多人都不知道WCF和WebService之间的关系.实际上WCF包含了WebService,这是一个很强 ...
- Delphi Excel
用delphi写excel文件 2007-03-18 21:12 1.引用: Excel2000, OleServer,Comobj, StdCtrls 2.声明变量: ExcelA ...
- shell脚本学习之$0,$?,$!等的特殊用法
变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 ...
- tableview 在ios8上面分割线不全的问题
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath ...
- ios专题 - openSSL
1 概述 1.1 产生背景 基 于万维网的电子商务和网上银行等新兴应用,极大地方便了人们的日常生活,受到人们的青睐.由于这些应用都需要在网络上进行在线交易,它们对网络通信的安全 性提出了更高的要求 ...
- angular2 组件之间通讯-使用服务通讯模式 2016.10.27 基于正式版ng2
工作中用到ng2的组件通讯 奈何官方文档言简意赅 没说明白 自己搞明白后 整理后分享下 rxjs 不懂的看这篇文章 讲很详细 http://www.open-open.com/lib/view/ope ...
- 时区之痒 - 从手机GPS模块获取的时间,真的是北京时间么?
去年互联网地图行业开始引入众包模式,国内比较大的地图商,比如四维图新.高德地图.百度地图纷纷开始推出UGC应用,众包给用户采集门址.公交站等信息,并按照工作量给与采集者一定的回报.我曾经玩过某德推出的 ...
- CSS3—CSS3和现代Web设计
1.1 现代Web设计理念 1.1.1 可访问性第一 同样一段内容, 可以用成千上万的方法为其设计样式, 但全世界的用户应该依然可以访问它们, 不管他们用什么方式去访问Web——无论手机.键盘控制器还 ...
- demo_03HTML5中的动画效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...