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/ ...
随机推荐
- IIS7报错:如果要使用托管的处理程序,请安装 ASP.NET
转载至码农SeraphWU IIS7报错:如果要使用托管的处理程序,请安装 ASP.NET 进入CMD 输入如下命令即可 "%WINDIR%\Microsoft.NET\Framework\ ...
- 《你不常用的c#之一》:略谈unsafe
转自csdn:http://blog.csdn.net/robingaoxb/article/details/6199508 msdn里讲到: “在 C# 中很少需要使用指针,但仍有一些需要使用的情况 ...
- Java随机生成定长纯数字或数字字母混合数
(转)Java随机生成定长纯数字或数字字母混合数 运行效果图: 具体实现代码
- Invalid segment BIN$xxx and dba_recyclebin was empty (回收站空,释放无效的BIN$xx空间)
近来有套库空间紧张,发现有很大BIN$开头的TABLE partition,index partition 类型的段,查询确认是2个月前删除的对象,手动清空过dba_recyclebin使用purge ...
- linux du 显示目录下的各个子目录的大小
use command du display estimate file space usage size of subdirectories [oracle@ahjcyl-db backup]$ ...
- ZOJ 1076 Gene Assembly(LIS+路径打印 贪心)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=76 题目大意:在一个DNA上,给定许多基因的起始位置和结束位置,求出这 ...
- Qt中使用信号和槽的一点心得
信号(Signal)与槽(Slot)-Qt中的典型机制 这一篇文章中都说得很详细了,这里不再重复,只说一点在实际使用中可能会遇到的问题. 1.一个信号不要同时连接几个槽函数,不然执行的顺序是随机的,最 ...
- phpExcel使用与中文处理教程
PHPExcel 是相当强大的 MS Office Excel 文档生成类库,当需要输出比较复杂格式数据的时候,PHPExcel 是个不错的选择.不过其使用方法相对来说也就有些繁琐. phpExcel ...
- jQuery 标签淡入淡出 个人随笔
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ecshop安装程序源码阅读-安装脚本(2)
检查环境变量: 程序目录:图片目录,数据目录,临时目录 模板目录下模板文件 数据库连接函数 数据库配置: 读取数据库列表 创建配置文件(数据库,语言,session有效期等) 创建数据表 创建初始化数 ...