A + B Problem II

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

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<iostream>
#include<cstring>
#include<string.h>
#include<cmath>
#include<algorithm>
typedef long long ll;
using namespace std;
#define N 1010
int main()
{
int n,k,i,j,flag;
char s1[N],s2[N];
int a[N],b[N];
int c[N];
cin>>n;
for(k=;k<=n;k++)
{
cin>>s1>>s2;
int len1=strlen(s1);
int len2=strlen(s2);
cout<<"Case "<<k<<":"<<endl<<s1<<" + "<<s2<<" = ";
memset(a,,sizeof(a));
memset(b,,sizeof(b));
int j=;
int jj=;
for(i=len1-;i>=;i--)
{
a[j]=s1[i]-'';
j++;
}
for(i=len2-;i>=;i--)
{
b[jj]=s2[i]-'';
jj++;
}
memset(c,,sizeof(c));
for(i=;i<=max(len1-,len2-);i++)
{
c[i]=a[i]+b[i]+c[i];
if(c[i]>)
{
c[i]=c[i]-;
c[i+]++;
}
}
flag=;
for(i=max(len1-,len2-);i>=;i--)
{
if(flag==&&c[i]==)
flag=;
else
{
cout<<c[i];
flag=;
}
}
if(k<n)
cout<<endl<<endl;
else
cout<<endl;
}
return ;
}

hdu 1002(大数)的更多相关文章

  1. hdu 1002大数(Java)

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

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

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

  3. HDU 1002 A - A + B Problem II (大数问题)

    原题代号:HDU 1002 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 原题描述: Problem Description I have a ...

  4. 大数加法~HDU 1002 A + B Problem II

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...

  5. hdu 1002 Java 大数 加法

    http://acm.hdu.edu.cn/showproblem.php?pid=1002 PE   由于最后一个CASE不须要输出空行 import java.math.BigInteger; i ...

  6. hdu 1002 A + B Problem II【大数加法】

    题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...

  7. HDU 1002 A + B Problem II (大数加法)

    题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...

  8. hdu 1002 A + B Problem II(大数)

    题意:就是求a+b (a,b都不超过1000位) 思路:用数组存储 第一道大数的题目,虽然很水,纪念一下! 代码: #include<cstdio> #include<cstring ...

  9. hdu 1002 java 大数相加

    package Main; //import java.io.InputStream; import java.math.BigDecimal; import java.util.Scanner; p ...

  10. HDU 1002:A + B Problem II(大数相加)

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

随机推荐

  1. python--8、socket网络编程

    socket socket可以完成C/S架构软件的开发.须知一个完整的计算机系统是由硬件.操作系统.应用软件三者组成,具备了这三个条件,一台计算机就可以工作了.但是要跟别人一起玩,就要上互联网(互联网 ...

  2. hadoop 安装问题总结

    安装启动步骤  [英语好的,直接手把手跟着来] http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/Sing ...

  3. eas之事件

    选择事件 选择事件是在选择块发生变化后发出.table.addKDTSelectListener(new KDTSelectListener(){    public void tableSelect ...

  4. DOM学习之图片库切换效果

    addloadevent(prepareplaceholder()) addloadevent(prepareGallery()) //页面加载完时执行函数 function addloadevent ...

  5. POJ3617 Best Cow Line【贪心】

    Description  给定长度为n的字符串S,要构造一个长度为n的字符串T.起初,T是空串,随后反复进行下列任意操作:  1.从S的头部删除一个字符,加到T的尾部  2.从S的尾部删除一个字符,加 ...

  6. [bzoj4766] 文艺计算姬 (矩阵树定理+二分图)

    传送门 Description "奋战三星期,造台计算机".小W响应号召,花了三星期造了台文艺计算姬.文艺计算姬比普通计算机有更多的艺 术细胞.普通计算机能计算一个带标号完全图的生 ...

  7. php 后端实现JWT认证方法

    JWT是什么 JWT是json web token缩写.它将用户信息加密到token里,服务器不保存任何用户信息.服务器通过使用保存的密钥验证token的正确性,只要正确即通过验证.基于token的身 ...

  8. Codeforces 851B/C

    B. Arpa and an exam about geometry 传送门:http://codeforces.com/contest/851/problem/B 本题是一个平面几何问题. 平面上有 ...

  9. 1.IDEA的安装

    .1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16.

  10. 00063_String类

    1.String类的概述 (1)String 类代表字符串: (2)Java 程序中的所有字符串字面值(如 "abc" )都作为此类的实例实现: (3)字符串是常量,它们的值在创建 ...