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. Java基础学习(二)——对象

    类:是抽象的概念集合,表示的是一个共性的产物,类之中定义的是属性和行为(方法): 对象:对象是一种个性的表示,表示一个独立的个体,每个对象拥有自己独立的属性,依靠属性来区分不同对象. 对象=实例 对象 ...

  2. 个人作业—Alpha测试

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/homework/3338 这个作业要求在哪里 htt ...

  3. js开发性能(一)

    随着js技术的发展,性能问题开始被越来越多的人关注,最近了解了一些关于前端性能的问题,这里主要讨论一下在js脚本加载和执行的过程中,我们应该怎么样来提高js的性能. js脚本的处理 初学前端的时候,我 ...

  4. day34-2 类和对象(重点)

    目录 类 定义类和对象 __dict__ 和__class__ 创建对象时的底层运作 定义对象独有的特征 init __slots__(了解) 给对象添加属性时的底层运作 类 分类/类别 上述的代码( ...

  5. Java子类对于父类中static方法的继承

    今天看到了Java中子类继承父类的一个相关讨论,在网上综合了各家的观点,写下了一篇简短的总结. 问题如下,在父类中含有staic修饰的静态方法,那么子类在继承父类以后可不可以重写父类中的静态方法呢? ...

  6. android studio: 为现有项目添加C++支持

    刚开始创建项目的时候并没有勾选“include C++ support” 选项: 后期增加步骤: 1.拷贝已有支持C++项目的CMakeLists.txt文件到现有项目的app目录下: 2.在app/ ...

  7. 【剑指Offer】2、替换空格

      题目描述:   请实现一个函数,将一个字符串中的每个空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. ...

  8. USACO 4.1 Fence Rails

    Fence RailsBurch, Kolstad, and Schrijvers Farmer John is trying to erect a fence around part of his ...

  9. [pytorch学习]2. 官网60分钟教程摘要

    https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html 1. Pytorch的基本单元,tensor,本质上和num ...

  10. poj 3469 最小割模板sap+gap+弧优化

    /*以核心1为源点,以核心2为汇点建图,跑一遍最大流*/ #include<stdio.h> #include<string.h> #include<queue> ...