A + B Problem II

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

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
Author
Ignatius.L
分析:高精度计算,大数相加!模版在博客中已给出,翻翻看,按照模版写就行了,要注意细节,空格的输出,因为这个PE了2次!
下面给出AC代码:
 #include <bits/stdc++.h>
using namespace std;
int main()
{
char a1[],b1[];
int a[],b[],c[];//a,b,c分别存储加数,加数,结果
int x,i,j,n;
int lena,lenb,lenc;
while(scanf("%d",&n)!=EOF)
{
for(j=;j<=n;j++)
{
memset(a,,sizeof(a));//数组a清零
memset(b,,sizeof(b));//数组b清零
memset(c,,sizeof(c));//数组c清零
scanf("%s%s",&a1,&b1);
lena=strlen(a1);
lenb=strlen(b1);
for(i=;i<=lena;i++)
a[lena-i]=a1[i]-'';//将数串a1转化为数组a,并倒序存储
for(i=;i<=lenb;i++)
b[lenb-i]=b1[i]-'';//将数串b1转化为数组a,并倒序存储
x=;//x是进位
lenc=;//lenc表示第几位
while(lenc<=lena||lenc<=lenb)
{
c[lenc]=a[lenc]+b[lenc]+x;//第lenc位相加并加上次的进位
x=c[lenc]/;//向高位进位
c[lenc]%=;//存储第lenc位的值
lenc++;//位置下标变量
}
c[lenc]=x;
if(c[lenc]==)//处理最高进位
lenc--;
printf("Case %d:\n",j);//格式要求吧!学着点
printf("%s + %s = ",a1,b1);//这也是格式要求吧!学着点
for(i=lenc;i>=;i--)
printf("%d",c[i]);
printf("\n");
if(j!=n)//对于2组之间加空行的情况
printf("\n");
}
}
return ;
}

java写法大数,真是有毒!

 import java.math.BigInteger;
import java.util.Scanner; public class Main { /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
//System.out.println("Hello World!");
Scanner in=new Scanner(System.in);
while(in.hasNextInt())
{
// int []arr=new int[3];
int n;
n=in.nextInt();
for(int i=1;i<=n;i++)
{
BigInteger a,b;
a=in.nextBigInteger();
b=in.nextBigInteger();
if(i<n)
{
System.out.println("Case "+i+":");
System.out.print(a+" + "+b+" = ");
System.out.println(a.add(b));
System.out.println();
}
else
{
System.out.println("Case "+i+":");
System.out.print(a+" + "+b+" = ");
System.out.println(a.add(b));
}
}
}
}
}

HDU 1002 A + B Problem II(高精度加法(C++/Java))的更多相关文章

  1. HDU 1002 - A + B Problem II - [高精度]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...

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

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

  3. hdu1002 A + B Problem II(高精度加法) 2016-05-19 12:00 106人阅读 评论(0) 收藏

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

  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. HDU 1002 A + B Problem II

    A + B Problem II   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted ...

  6. HDU 1002 A + B Problem II(大整数相加)

    A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  7. HDU 1002 A + B Problem II( 高精度加法水 )

    链接:传送门 题意:A + B 高精度,板子题 /************************************************************************* & ...

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

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

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

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

随机推荐

  1. CSS文字不换行,溢出省略

    white-space:nowrap; overflow:hidden; text-overflow:ellipsis;

  2. MySQL创建一个固定频率执行且自定义"开始"时间的定时任务event

    drop event if exists evt_test;create event evt_teston schedule every 10 SECOND  -- 每10秒执行一次(second可以 ...

  3. JS画几何图形之五【过圆外一点作切线】

    样例:http://www.zhaojz.com.cn/demo/draw9.html 依赖:[点].[直线].[圆] //画切线 //point 圆外的一点 //dot 圆心 //r 半径 func ...

  4. lesson - 11 课程笔记

    一.sed  作用: sed 是一种流编辑器,它是文本处理中非常重要的工具, 能够完美的配合正则表达式使用.处理时,把当前处理的行存储在临时缓冲区中, 称为“模式空间(pattern space)”, ...

  5. g4e基础篇#1 什么是版本控制系统

    g4e 是 Git for Enterprise Developer的简写,这个系列文章会统一使用g4e作为标识,便于大家查看和搜索. 章节目录 前言 1. 基础篇: 为什么要使用版本控制系统 Git ...

  6. Nginx学习之配置RTMP模块搭建推流服务

    写在开始 小程序升级实时音视频录制及播放能力,开放 Wi-Fi.NFC(HCE) 等硬件连接功能.同时提供按需加载.自定义组件和更多访问层级等新特性,增强了第三方平台的能力,以满足日趋丰富的业务需求. ...

  7. jquery隐藏域赋值

    <input type="hidden" id="id" value="value"> $("#id的值") ...

  8. 纯CSS实现箭头、气泡让提示功能具有三角形图标(简单实例)

    <style type="text/css"> /*向上箭头,类似A,只有三个边,不能指定上边框*/ .arrow-up { width: 0px; height: 0 ...

  9. 关于md5的使用方法

    本周工作,学习中用到了,md5. 在我们需要用到md5密码的时候,可以使用: System.Web.Security.FormsAuthentication.HashPasswordForStorin ...

  10. C#用DataTable实现Group by数据统计

    http://www.cnblogs.com/sydeveloper/archive/2013/03/29/2988669.html 1.用两层循环计算,前提条件是数据已经按分组的列排好序的. Dat ...