A + B Problem II

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

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<string.h>
#define MAX 1100
char str1[MAX],str2[MAX];
int a[MAX],b[MAX];
int main()
{
int n,m,j,i,s,t,l1,l2,k,ok;
scanf("%d",&t);
k=1;
while(t--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%s%s",str1,str2);
l1=strlen(str1);
l2=strlen(str2);
for(i=l1-1,j=0;i>=0;i--)
{
a[j]=str1[i]-'0';
j++;
}
for(i=l2-1,j=0;i>=0;i--)
{
b[j]=str2[i]-'0';
j++;
}
n=0;
if(l1<l2)
{
n=l1;
l1=l2;
l2=n;
}
for(i=0;i<l1;i++)
{
a[i]=a[i]+b[i];
if(a[i]>=10)
{
a[i]-=10;
a[i+1]++;
}
}
ok=0;
if(a[l1]>0)
{
ok=1;
}
printf("Case %d:\n",k++);
printf("%s + %s = ",str1,str2);
if(!ok)
for(i=l1-1;i>=0;i--)
printf("%d",a[i]);
else
for(i=l1;i>=0;i--)
printf("%d",a[i]);
printf("\n");
if(t)
printf("\n");
}
return 0;
}

hdoj 1002 A + B Problem II【大数加法】的更多相关文章

  1. HDU 1002 A + B Problem II(高精度加法(C++/Java))

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

  2. hdoj 1002 A + B Problem II

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

  3. A + B Problem II 大数加法

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

  4. hdoj 1002 A + B Problem II 高精度 java

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

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

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

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

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

  7. 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

    数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...

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

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

  9. Problem : 1002 ( A + B Problem II )

    经验总结:一定要注意输出的格式,字符的空格,空行,一定要观察清楚.如本题的最后一个输出结果后面没有空行.最后代码实现的时候需要判断一下,代码如下 !=n) cout<<endl; Prob ...

随机推荐

  1. Web模板引擎本质前奏

    执行字符串表示的函数,并为该函数提供全局变量: #! /usr/bin/env python3 namespace = {'name': 'zingp', 'data': [16, 19, 25]} ...

  2. 由 OR 引起的死循环

    在客商迁移测试时,程序一旦开始执行就不能自动停止.只能通过手动中断应用服务器的进程来停止.检查迁移的一个表,这个表迁移前没有数据,迁移最多会插入3w条左右数据,但是迁移过程执行2个多小时候再看,已经有 ...

  3. C# 中经常用到的HTTP请求类,已封装get,post,delete,put

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  4. 将十进制的颜色制转换成ARGB

    将一个十进制的颜色值转换成具体的ARGB 格式,起初,这看起来有些难,一直找不到方法,在网上也找不到具体的资料,最后在同事的指导下成功完成的转换,现分享出来,供大家参考,具体转换方法如下: /// & ...

  5. C#中Socket编程解决应用程序直接的通信

    using System;using System.Collections.Generic;using System.Linq;using System.Text; using System.Net; ...

  6. Hibernate学习笔记--环境搭建及运行

    1.hibernate开发包下载 http://sourceforge.net/projects/hibernate/files/ 如果不能访问请用代理http://dongtaiwang.com/l ...

  7. 工作总结:文件对话框的分类(C++)

    原文地址:http://www.jizhuomi.com/software/173.html 文件对话框分为打开文件对话框和保存文件对话框,相信大家在Windows系统中经常见到这两种文件对话框.例如 ...

  8. hdu 1827

    强连通分量——tarjin算法: 这题的思路就是找出多少个出度为0的连通分量,结果就是这些连通分量的元素的最小值相加: 一道很简单的题,改了我好久,= =!~ 贴代码: #include<cst ...

  9. VS2010 C# 调用Web Service .

    转自:http://blog.csdn.net/fenglailea/article/details/7262566 打开VS2010,打开"文件-新建-网站",选择"A ...

  10. X86汇编快速入门

    http://www.cnblogs.com/YukiJohnson/archive/2012/10/27/2741836.html