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) ...
随机推荐
- ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置
一.介绍 二.1.linear_layout.xml <?xml version="1.0" encoding="utf-8"?> <Line ...
- LCMS
LCMS(LearningContent Management System) 即学习内容管理系统
- EL表达式 JSTL中的常用EL函数 动态数据的国际化
ELppt: EL 全名为Expression Language.EL主要作用: 获取数据: •EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数据.( ...
- 解锁windowsphone设备遇到的错误:检查Miscrosoft账户凭据、请重新注册 0x80004005 解决方案
本篇文章主要讲在解锁windowsphone设备时遇到的错误 Error1:登录windowsphone开发人员中心时出错,请检查您的miscrosoft账户凭据 Error2:注册您的手机时出现未知 ...
- sql 的错误处理功能很弱
--下面演示了SQL错误处理的脆弱性--邹建 --演示1--测试的存储过程1create proc p1asprint 12/0if @@error<>0print '发生错误1' sel ...
- android MIPI屏 导航栏丢失
/**************************************************************************** * android MIPI屏 导航栏丢失 ...
- Spring Autowire自动装配介绍
在应用中,我们常常使用<ref>标签为JavaBean注入它依赖的对象.但是对于一个大型的系统,这个操作将会耗费我们大量的资源,我们不得不花费大量的时间和精力用于创建和维护系统中的< ...
- postgreSQL数据类型转换字符串和数值
1.将数值转成字符串类型 方法1:调用to_char(int, text)函数,int为要转换值,text为数值格式化模式,其中模式描述为: 模式 描述 9 带有指定数值位数的值 0 带前导零的值 ...
- 非均匀B样条拟合MATLAB程序
直接上代码,多的不再说了. %------------------非均匀B样条拟合MATLAB程序----------------- clear k=; x=load('data.txt'); [n, ...
- 明修栈道,暗渡陈仓----之私募一哥徐翔新玩法 z
前言:去年以来,因徐翔和宁电突然举牌资质平平的 000692 惠天热电,引起本人的兴趣,陆陆续续花了比较多的时间和精力去研究和跟踪000692惠天热电,期间也两次亲自去沈阳调研,从一些台前幕后人士那里 ...