题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1002

A + B Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 409136    Accepted Submission(s): 79277

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

 
思路:
采用字符数组储存两个加数,模拟小学的加法竖式计算
注意点:
1.俩个加数长度不等的时候,长度短的加数前面加0,0的个数为二者长度相减的绝对值
2.输出格式问题,只有输出最后一组数据的结果的时候,一个回车,其余都是两个回车
代码如下:
#include<bits/stdc++.h>
int main()
{
int n;
scanf("%d",&n);
int y=;
while(y<=n)
{
char a[]= {''},b[]= {''},C[],A[],B[];
getchar();
scanf("%s %s",a,b);
int l1=strlen(a);
int l2=strlen(b);
if(l1>l2)
{
int k=l1-l2;
char d[k];
for(int i=; i<k; i++)
d[i]='';
d[k]='\0';
B[]='\0';
strcat(B,d);
strcat(B,b);
A[]='\0';
strcat(A,a);
}
else if(l1<l2)
{
int k=l2-l1;
char d[k];
for(int i=; i<k; i++)
d[i]='';
d[k]='\0';
A[]='\0';
strcat(A,d);
strcat(A,a);
B[]='\0';
strcat(B,b);
}
else if(l2==l1)
{
A[]='\0';
B[]='\0';
strcat(A,a);
strcat(B,b);
}
l1=strlen(A);
l2=strlen(B);
int k=,cc=;
for(int i=l1-,j=l2-; i>=&&j>=; i--,j--)
{
int t=A[i]-''+B[j]-''+cc;
if(t>=)
{
cc=;
t=t-;
}
else
{
cc=;
}
C[k]=t+'';
k++;
}
if(cc==)
{
C[k]='';
C[k+]='\0';
}
else
{
C[k]='\0';
}
int l3=strlen(C);
printf("Case %d:\n",y);
printf("%s + %s = ",a,b);
for(int i=l3-; i>=; i--)
{
printf("%c",C[i]);
}
printf("\n");
if(y!=n)
printf("\n");
y++;
}
return ;
}

HDU1002 A + B Problem II 大数问题的更多相关文章

  1. hdu1002 A + B Problem II(大数题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...

  2. HDU1002 -A + B Problem II(大数a+b)

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu1002 A + B Problem II[大数加法]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1002 题干 代码和解释 由题意这是一个涉及到大数的加法问题.去看了一眼大数加法的方法感觉头很大,然后突然发现Java可以流氓解决大数问题,毅 ...

  4. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  5. hdu1002 A + B Problem II(高精度加法) 2016-05-19 12:00 106人阅读 评论(0) 收藏

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. [HDU1002] A + B Problem II

    Problem Description I have a very simple problem for you. Given two integers A and B, your job is to ...

  7. A + B Problem II 大数加法

    题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...

  8. A + B Problem II(大数加法)

    一直格式错误,不想改了,没A #include <iostream> #include <stdio.h> #include <string.h> #include ...

  9. HDU 1023 Train Problem II 大数打表Catalan数

    一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...

随机推荐

  1. 177. [USACO Jan07] 有限制的素数

    177. [USACO Jan07] ★   输入文件:qprime.in   输出文件:qprime.out   简单对比 时间限制:1 s   内存限制:128 MB Farmer John 开始 ...

  2. 分布式文件系统比较出名的有HDFS  和 GFS

    分布式文件系统比较出名的有HDFS  和 GFS,其中HDFS比较简单一点.本文是一篇描述非常简洁易懂的漫画形式讲解HDFS的原理.比一般PPT要通俗易懂很多.不难得的学习资料. 1.三个部分: 客户 ...

  3. 《Pro Git》轻松学习版本控制

    转自 https://kindlefere.com/post/333.html 什么是“版本控制”?我为什么要关心它呢?版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.在 ...

  4. d3js layout 深入理解

    D3 layouts help you create more advanced visualisations such as treemaps: D3 layouts帮助您创造更加高级复杂的可视化图 ...

  5. ExpressRoute 线路和路由域

    你必须订购一条 ExpressRoute 线路 ,以通过连接提供商将你的本地基础结构连接到 Azure.下图提供了你的 WAN 与 Azure 之间的连接的逻辑表示形式. ExpressRoute 线 ...

  6. Oracle EBS OM发运行状态自动更改

  7. node环境和浏览器的区别

    一.全局环境下this的指向 在node中this指向global而在浏览器中this指向window,这就是为什么underscore中一上来就定义了一 root: 1 var root = typ ...

  8. 使用vue做项目

    使用vue做项目需要用到node.js的npm来管理包 所以我们需要先下载node.js然后通过node的npm来管理包  安装完 nodejs后 我们需要执行 npm install vue-cli ...

  9. 【原创】使用Java进行Clob转String字符串

    背景 oracle字段类型varchar2最大长度4000,超过的怎么办 解决 使用clob类型,大字段,无长度限制 问题 使用Java的JDBC读取的RS获取的clob类型无法正常使用,封装的rs. ...

  10. October 06th 2017 Week 40th Friday

    The greatest ideal man can set before himself is self-perfection. 一个人最高的理想是自我完善. To be better than t ...