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) ...
随机推荐
- MVC @Html.DropDownListFor 默认值
今天在做MVC 的 @Html.DropDownListFor 的时候,本来数据库中读取到的值是HK,但是 @Html.DropDownListFor的起始默认值始终是“请选择国家”,搞了一个下午, ...
- ajax跨域访问的解决方案
今天的工作中要访问摄像机内部的一个web站点,这就涉及到jquery的ajax跨域访问的问题.我使用的是jquery1.7的版本,下面总结如下: 问题一:一开始用IE调试,总是返回No Transpo ...
- 使用FileZilla Server轻松搭建个人FTP服务器
Linux平台下快速搭建FTP服务器 服务器FTP Server环境搭建 针对以上遇到的问题的解决方案如下: 1)如何上传文件到云服务器上 关于这个问题,我首先想到的是使用FileZ ...
- Android:布局实例之常见用户设置界面
实现效果: 整理思路: 1.控件:文字TextView 和 右箭头ImageView 2.因为考虑到点击效果,设计为:最外层为全圆角,内层有四种情况,分别为上圆角.无圆角.下圆角和全圆角. 3.内层样 ...
- SQL Server中的分页
sqlserver2000时的分页思路 .分页查询时,首先将数据排序 select * from MyStudent order by fid desc .取第一页数据 * from MyStuden ...
- Android开发之极光推送基本步骤
[转]:http://wyong.blog.51cto.com/1115465/1402842 两天在研究推送的问题,后来确定了用极光推送,本人将整个过程整理一下: 1.到极光官网注册账号:https ...
- 'ascii' codec can't encode characters in position 0-8: ordinal not in range(128)的解决办法
使用的python2.7,运行的时候出现了'ascii' codec can't encode characters in position 0-8: ordinal not in range(128 ...
- poj 水题系列
题目:http://poj.org/problem?id=3006 筛选法求素数 #include <iostream> #include<cstdio> #include&l ...
- POJ2528 线段树的区间操作
首先应该对该[0,10000000]进行离散化 即先将点集进行排序,然后从小到大缩小其中的间距,使得最后点数不会超过2*n 然后就是线段树操作 只需进行染色,然后最后用nlgn进行一个个查询颜色记录即 ...
- POJ 1815 Friendship ★(字典序最小点割集)
[题意]给出一个无向图,和图中的两个点s,t.求至少去掉几个点后才能使得s和t不连通,输出这样的点集并使其字典序最大. 不错的题,有助于更好的理解最小割和求解最小割的方法~ [思路] 问题模型很简单, ...