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/ ...
随机推荐
- 消息处理之EventBus ——使用篇
以前的几篇文章简单的介绍了一下UI线程和子线程之间的线程通信利器Handler,以及顺便介绍了一下SyncTask和HeadlerThread.这里介绍另一线程通信利器EventBus. EventB ...
- python基础知识六
博客园的博文对每篇博文的长度似乎做了限制 面向对象编程, 在程序何种,根据操作数据的函数或语句块来设计程序.这被成为面向过程的编程.还有一种把数据和功能结合起来,用称为对象的东西包裹起来组织组织程序的 ...
- iOS 身份证最后一位是X,输入17位后自动补全X(转)
非原创,转载自http://blog.csdn.net/l2i2j2/article/details/51542028如果身份证最后一位是X,输入17位后自动补全X// textField代理方法 - ...
- UITextField 对输入金额的约束
[2016/1/18更新] -- 五个人辛辛苦苦干了一年的项目终于上线了,今天有空看了一下正则表达式教程,然后开始rebuild之前的种种对字符串的约束,首先就从这个金额输入框开始吧,修改后的代码如下 ...
- 数据库学习(整理)----6--Oracle如何快速备份和多次备份数表数据
1.说明: 这里假设一种应用场景! 假设,银行系统中有大量的数据需要及时备份,如何才能快速高效呢! 条件需求: (1).不能设置同步锁(设置的会影响银行正常业务进行!使得银行系统处于维护状态,这是不 ...
- Windows phone 之Socket
服务器端: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...
- windows下node.js+sublime中安装coffeescript
node.js中安装Coffeescript 1.我的node.js安装目录 2.node.js 全局模块所在目录 3.node.js安装coffeescript npm install -g c ...
- FileStream读写文件流
用FileStream 读取文件流并显示给文件内容 string p = @"C:\Users\Administrator\Desktop\1.txt"; FileStream f ...
- php多行字符串输出
$content_header =<<<CONTENT_HEADER <section class="content-header"> <h ...
- phpcms安装完成后总是跳转到install/install.php
很多人在本地安装phpcms后总是跳转到install/install.php.由于很多人是第一次使用phpcms,不知道为何会出现这个错误.出现这个大都是phpcms的缓存所致. 如何解决ph ...