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创建Excel-DEMO

    import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Out ...

  2. Android 判断app是否安装

    1. private boolean isAppInstalled(Context context, String uri) { PackageManager pm = context.getPack ...

  3. jQuery的基本概念与高级编程

    年创建的一个年月面世的1.5.2版本.作为一个JavaScript库,jQuery极大程度上解决了浏览器的兼容性问题,能够在IE 6.0 +.FF 2.0 +.Safari 3.0 +.Opera 9 ...

  4. Ceph 文件系统的安装

    yum install -y wget wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87 ...

  5. 重新理解 Monad

    对于大多数刚刚入门函数式编程的同学来说,monad(单子.又叫单体)可能是这里面的一道坎.你可能对 map . flatMap 以及 filter 再熟悉不过,可是到了高阶的抽象层次上就又会变得一脸懵 ...

  6. 分块编码(Transfer-Encoding: chunked)VS Content-length

    参考链接: HTTP 协议中的 Transfer-Encoding 分块传输编码 https://www.cnblogs.com/xuehaoyue/p/6639029.html 一.背景: 持续连接 ...

  7. taglib遍历foreach循环list集合

    第一部导入jstl.jar 第二步进行list传输: package com.aaa.servlet; import com.aaa.dao.IUserDAO; import com.aaa.dao. ...

  8. BZOJ 1594: [Usaco2008 Jan]猜数游戏 线段树 + 思维 + 二分

    Code: #include<bits/stdc++.h> #define maxn 3000000 using namespace std; void setIO(string s) { ...

  9. Selenium3+python 加载Firefox配置

    有小伙伴在用脚本启动浏览器时候发现原来下载的插件不见了,无法用firebug在打开的页面上继续定位页面元素,调试起来不方便 . 加载浏览器配置,需要用FirefoxProfile(profile_di ...

  10. java环境搭建心得

     右击此电脑,点击属性, 在打开的电脑系统对话框里发电机i直接点击左侧导航里的[高级系统设置]在打开的电脑系统属性对话框里直接点击下面的[环境变量] 打开环境变量对话框后,直接点击系统变量下面的新建, ...