hdu 1002(大数)
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
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.
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.
1 2
112233445566778899 998877665544332211
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(大数)的更多相关文章
- hdu 1002大数(Java)
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...
- HDU 1002 A - A + B Problem II (大数问题)
原题代号:HDU 1002 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 原题描述: Problem Description I have a ...
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- hdu 1002 Java 大数 加法
http://acm.hdu.edu.cn/showproblem.php?pid=1002 PE 由于最后一个CASE不须要输出空行 import java.math.BigInteger; i ...
- hdu 1002 A + B Problem II【大数加法】
题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...
- HDU 1002 A + B Problem II (大数加法)
题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...
- hdu 1002 A + B Problem II(大数)
题意:就是求a+b (a,b都不超过1000位) 思路:用数组存储 第一道大数的题目,虽然很水,纪念一下! 代码: #include<cstdio> #include<cstring ...
- hdu 1002 java 大数相加
package Main; //import java.io.InputStream; import java.math.BigDecimal; import java.util.Scanner; p ...
- HDU 1002:A + B Problem II(大数相加)
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- Android中Button四种点击事件实现方式
1.Xml添加监听属性,这里添加的doClick. <Button android:id="@+id/bt1" android:layout_width="wrap ...
- 【Oracle】truncate分区表
分区表是生产中常用的一种表,它可以实现数据的按类存放,极大的提高了数据的查询及维护.当我们不需要某一分区的数据时,可以采用truncate来清空分区.实验如下: SQL)) partition by ...
- YTBro Video 2016-07-30 Sat
明日天气:多云转阴,32~24度 运动向 健身 20中极致疯狂的俯卧撑,新手请勿尝试 跑酷 大神放大招,招招见血,不信你看 赛事 2016年世界室内田径锦标赛 男子4×400接力决赛 台球 RP集中爆 ...
- 针对Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解决方案
背景:本项目使用JDK1.8 编译maven工程的时候出现如下错误: Failed to execute goal org.apache.maven.plugins:maven-compiler-pl ...
- PowerShell 解决红字一闪而过问题
起因 起初只想在 win7上实现 pause 效果而已 cmd /c pause | out-null 结果只能看到红字一闪而过 打开 PowerShell ISE 进行调试 这次清楚的看到红字提示 ...
- Hadoop-2.2.0集群部署时live nodes数目不对的问题
关于防火墙,hadoop本身配置都确定没任何问题,集群启动不报错,但打开50070页面,始终live nodes数目不对,于是我尝试/etc/hosts文件配置是否存在逻辑的错误: 127.0.0.1 ...
- js中的数组遍历
js中的数组遍历是项目中经常用到的,在这里将几种方法做个对比. ! for循环:使用评率最高,也是最基本的一种遍历方式. let arr = ['a','b','c','d','e']; for (l ...
- hadoop中的job.setOutputKeyClass与job.setMapOutputKeyClass
初学mr时,觉得没什么,但是学了一段时间,重新复习时发现程序中mr程序中一般都会有 hadoop中的job.setOutputKeyClass(theClass)与job.setOutputValue ...
- Python之CSV模块
1. CSV简介 CSV(Comma Separated Values)是逗号分隔符文本格式,常用于Excel和数据库的导入和导出,Python标准库的CSV模块提供了读取和写入CSV格式文件的对象. ...
- html表单练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...