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 ...
随机推荐
- Mybatis解析动态sql原理分析
前言 废话不多说,直接进入文章. 我们在使用mybatis的时候,会在xml中编写sql语句. 比如这段动态sql代码: <update id="update" parame ...
- 模拟MVC-WebForm实现ModelBinding
(一) 前言 用ASP.NET MVC的时候,我们都 ...
- Mininet在创建拓扑的过程中为什么不打印信息了——了解Mininet的log系统
前言 写这篇博客是为了给我的愚蠢和浪费的6个小时买单! 过程原因分析 我用Mininet创建过不少拓扑了,这次创建的拓扑非常简单,如下图,创建拓扑的代码见github.在以前的拓扑创建过程中,我都是用 ...
- Middleware的艺术
定义 Middleware直译叫中间件,目前在百度上很难找到一个简单明了的含义解释,.Net下以前也比较难以看到它的身影,但在Microsoft.Owin里,多个地方都看到MiddleWare,我近来 ...
- [BZOJ1579][Usaco2009 Feb]Revamping Trails 道路升级(二维最短路问题)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1579 分析: 设d[i][j]表示从1走到i.改了j条边的最短路径长度 如果设i相连的 ...
- C# WinForm捕获全局异常
网上找的C# WinForm全局异常捕获方法,代码如下: static class Program { /// <summary> /// 应用程序的主入口点. /// </summ ...
- hihocoder [Offer收割]编程练习赛4
描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...
- Activity之多启动图标
如果想要Activity有多个启动图标,只需要在manifest.xml文件中配置一下就可以了,直接上代码: 1 <application 2 android:allowBackup=" ...
- 【Spring】构建Springboot项目 实现restful风格接口
项目代码如下: package hello; import org.springframework.boot.SpringApplication; import org.springframework ...
- 64-who 简明笔记
显示已登录用户的信息 who [options] who am i who程序显示在本地系统上登录的用户的信息.这些信息包括每个用户的用户名.终端设备.登录时间和相应的远程主机名(如果可应用) 参数 ...