HDU 1002 A + B Problem II
A + B Problem II
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 16104 Accepted: 4547
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
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
思路:
把数值每一位拆开存进数组,利用ASCII码转换数据,然后进行相加。
#include<stdio.h>
#include<string.h>
int main()
{
char a[1003];
char b[1003];
char ans[1003];
int T;
scanf("%d",&T);
int cas = 0 ;
while(T--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(ans,0,sizeof(ans));
scanf("%s",a);
scanf("%s",b);
strrev(a);
strrev(b);
int i;
for(i = 0 ; a[i]&&b[i];i++)
{
ans[i]+=a[i]+b[i]-48;
if(ans[i]>'9'){
ans[i+1]++;
ans[i]-=10;
}
}
while(a[i]){
ans[i]+=a[i];
if(ans[i]>'9'){
ans[i+1]++;
ans[i]-=10;
}
i++;
}
while(b[i]){
ans[i]+=b[i];
if(ans[i]>'9'){
ans[i+1]++;
ans[i]-=10;
}
i++;
}
if(ans[i]==1)ans[i]+=48;
strrev(ans);
strrev(a);
strrev(b);
if(cas)printf("\n");
printf("Case %d:\n",++cas);
printf("%s + %s = %s\n",a,b,ans);
}
}
HDU 1002 A + B Problem II的更多相关文章
- 抓起根本(二)(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) ...
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- HDU 1002 - A + B Problem II - [高精度]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...
- hdu 1002.A + B Problem II 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- 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(AC代码)
#include <stdio.h> #include <string.h> #define MAX 1009 int main() { },b[MAX]={}; ,z=,r= ...
- hdu 1002 A + B Problem II【大数加法】
题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...
随机推荐
- ASP.MVC EASY UI 入门之 —— Tree & ComboTree
1.常规的EASY UI的tree和comboTree代码基本是官方的DEMO都有的,虽然很简单,但是还是要实践的做一次,才能更清晰的了解和使用它!先上效果图 因为用的是code first,所以数据 ...
- js的一些冷门的用法
1.delete 2.void 0 3.>>> 4.>>0 字符串转为数字 5.[] == ![] 6.
- struct socket 结构详解
Socket数据结构网络协议CC++ 用户使用socket系统调用编写应用程序时,通过一个数字来表示一个socket,所有的操作都在该数字上进行,这个数字称为套接字描述符.在系统调用 的实现函 ...
- Hibernate 的dialect 大全
RDBMS 方言 DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS3 ...
- java/c# 判断点是否在多边形区域内
java/c# 判断点是否在多边形区域内 年06月29日 ⁄ 综合 ⁄ 共 1547字 ⁄ 字号 小 中 大 ⁄ 评论关闭 最近帮别人解决了一个问题,如何判断一个坐标点,是否在多边形区域内(二维). ...
- java中的@Override标签,小细节大作用
转载:http://www.cnblogs.com/octobershiner/archive/2012/03/09/2388370.html 一般用途 ...
- 揭秘PHP匿名函数
揭秘PHP匿名函数 定义:匿名函数就是没有名字的函数. 有2种形式的匿名函数: 形式1:将一个匿名函数"赋值"给一个变量--此时该变量就代表该匿名函数了! 形式2: 是直接将一个匿 ...
- Spring mvc-异常javax.servlet.ServletException: Could not resolve view with name 'xxx' in servlet with name 'spring'
最近使用spring mvc开发项目,遇到一个问题: javax.servlet.ServletException: Could not resolve view with name 'ok' in ...
- Android NDK开发
Android NDK 开发教程(极客学院) 一.Android NDK环境搭建 使用最新ndk,直接抛弃cygwin,以前做Android的项目要用到NDK就必须要下载NDK,下载安装Cygwin( ...
- 理解 Java 的三大特性之多态
面向对象编程有三大特性:封装.继承.多态. 封装隐藏了类的内部实现机制,可以在不影响使用的情况下改变类的内部结构,同时也保护了数据.对外界而已它的内部细节是隐藏的,暴露给外界的只是它的访问方法. 继承 ...