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. 用CSS伪类制作一个不断旋转的八卦图?

    前言 介绍一下如何制作一个不断旋转的八卦图.快速预览代码及效果,点击:八卦图 代码如下: HTML部分 <!DOCTYPE html> <html> <head> ...

  2. 总结:Ruby里是值传递还是引用传递

    在ruby中一切都是对象,而你向方法中传递的实质上是对象的引用( object-reference).ruby中变量都是对象的引用. 先来看 def pref2(agr) agr.downcase e ...

  3. Deutsch lernen (05)

    1. die Wahrheit, -en 真理:  - 真言,实情 Wir sollen die Wahrheit festhalten. 坚持:紧握 Im Wein liegt Wahrheit. ...

  4. Oracle数据库的导入和导出

    Oracle数据库的导入和导出,是一项重要的的技术活,不但解决了数据库的导入导出,更方便快捷的获得数据. 使用imp和exp导入导出数据 使用exp导出数据 存放目录为\ORACLE_HOME\BIN ...

  5. EKF优化:协方差coff计算公式、意义、Code优化

    复习!复习! 原文链接:http://blog.csdn.net/goodshot/article/details/8611178 1.代码: Matlab相关系数的意义: Eigen::Matrix ...

  6. Maven服务器的使用之Maven桌面项目和Maven Web项目的创建

    Maven的使用 Maven功能强大, 可以参与管理软件的整个生命周期. Java软件开发中的jar包管理更是Maven的绝技. 1.创建Maven桌面项目 1.1 选择菜单创建Maven项目 1.2 ...

  7. We wanted {"required":["value"]} and you sent ["text","value","id","sessionId"]

    重装python pycharm后再次执行以前执行没有问题的Appium脚本报错 We wanted {"required":["value"]} and yo ...

  8. mysql主从机制的部署与应用

    部署mysql主从复制 Mysql master ip: 192.168.30.25   一主两从 Mysql slave ip: 192.168.30.24 Mysql slave ip:192.1 ...

  9. luogu P2422 良好的感觉 单调栈

    Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long using namespace std; v ...

  10. TensorFlow学习笔记----安装(1)

    在入门前,推荐一个博客链接:https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/ Windows下tensorflow ...