hdoj 1002 A + B Problem II
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 242959 Accepted Submission(s):
46863
integers A and B, your job is to calculate the Sum of A + B.
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.
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.
Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
注意给数组清零
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int m,j,n,i,l1,l2,t,k=1;
char s1[1100];
char s2[1100];
int s3[1100];
int s4[1100];
scanf("%d",&n);
while(n--)
{
scanf("%s %s",s1,s2);
memset(s3,0,sizeof(s3)); //给数组清0
memset(s4,0,sizeof(s4));
l1=strlen(s1);
l2=strlen(s2);
t=0;
for(j=l1-1,i=0;j>=0;j--,i++)
s3[i]=s1[j]-'0'; //将字符串转换为数字
for(j=l2-1,i=0;j>=0;i++,j--)
s4[i]=s2[j]-'0';
for(i=0;i<1100;i++)
{
s3[i]+=s4[i];
if(s3[i]>=10) //对各位求和
{
s3[i]-=10;
s3[i+1]++;
}
}
printf("Case %d:\n",k++);
printf("%s + %s = ",s1,s2);
for(i=1099;i>=0;i--)
if(s3[i]!=0)
break;
for(;i>=0;i--)
printf("%d",s3[i]);
printf("\n");
if(n>0)
printf("\n");
}
return 0;
}
hdoj 1002 A + B Problem II的更多相关文章
- hdoj 1002 A + B Problem II【大数加法】
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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) ...
- Problem : 1002 ( A + B Problem II )
经验总结:一定要注意输出的格式,字符的空格,空行,一定要观察清楚.如本题的最后一个输出结果后面没有空行.最后代码实现的时候需要判断一下,代码如下 !=n) cout<<endl; Prob ...
- 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...
- HDU 1002 A + B Problem II(高精度加法(C++/Java))
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hduoj 1002 A + B Problem II
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目描述如下: A + B Problem II Time Limit: 2000/1000 M ...
- HDU 1002 A + B Problem II
A + B Problem II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16104 Accepted ...
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- HPU 1002 A + B Problem II【大数】
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 李洪强iOS开发之OC常见错误汇总
// // main.m // 16 - 常见错误汇总 // // Created by vic fan on 16/7/13. // Copyright © 2016年 李洪强. All r ...
- png24是支持Alpha透明的。。。。。。
这个可能跟每个人使用切图软件有关. 1.Photoshop 1)只能导出布尔透明(全透明或者全不透明)的PNG8. 2)能导出alpha透明(全透明,全不透明,半透明)的PNG24. ...
- 关于PHP写APP接口的安全问题探讨(一)
在探讨这个问题之前,先要确认一点的是,作为一名互联网Coder,无论你是前端或者后端你都要对http请求要有一定的了解,知道http特性,要清楚的了解http里面的Request与Response是什 ...
- 双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计
前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构. 架构简介 此架构主要是由ke ...
- 219. Contains Duplicate II
题目: Given an array of integers and an integer k, find out whether there are two distinct indices i a ...
- 转XMLHelper
http://www.cnblogs.com/lixyvip/archive/2009/09/16/1567929.html using System; using System.Collection ...
- CenOS7.1安装VNC——让win7远程桌面linux
参考:http://wic.xingning.gov.cn/blog/29 https://linux.cn/article-5335-1.html 1.检查是否安装VNC, rpm -q tiger ...
- 【转】Android Service被关闭后自动重启,解决被异常kill 服务
http://www.kaifajie.cn/android/10182-2.html 每次调用startService(Intent)的时候,都会调用该Service对象的onStartComman ...
- NPOI的测试代码
NPOI\testcases\main\testcases vs10.csproj 需要注意,重新引用一下NPOI类库 需要注意的是,测试项目,使用了NUnit 找到测试项目下的SS文件夹,再定位到U ...
- mysqld -install命令时出现install/remove of the service denied错误的原因和解决办法
原因:没有使用管理员权限 解决方法:使用管理员权限打开cmd,然后运行mysqld -install,服务安装成功