A + B Again
来源:互联网 发布:淘宝模拟试衣服 编辑:程序博客网 时间:2024/05/17 04:40
Problem Description
There must be many A + B problems in our HDOJ , now a new one is coming.
Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.
Easy ? AC it !
Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.
Easy ? AC it !
Input
The input contains several test cases, please process to the end of the file.
Each case consists of two hexadecimal integers A and B in a line seperated by a blank.
The length of A and B is less than 15.
Each case consists of two hexadecimal integers A and B in a line seperated by a blank.
The length of A and B is less than 15.
Output
For each test case,print the sum of A and B in hexadecimal in one line.
Sample Input
+A -A
+1A 12
1A -9
-1A -12
1A -AA
Sample Output
0
2C
11
-2C
-90
题目求的是十六进制的加法。刚开始想的是把十六进制转化为十进制,进行加法运算后,再转化为十六进制。
所以这题可以直接用十六进制输入,然后进行十六进制的运算(其实不管是什么进制,在计算机中都是以二进制来计算的,只是按输入输出的格式不同,而强制转化为其它的进制),就像十进制的加法一样。
这里要注意的是输入小于15位,结果超过了二进制中的32位而小于64位。所以这里用__int64的类型。输入输入出格式就是(%I64x,%I64X)。由于%I64X,不能输出负数,所以负数的输出要做处理。
1 #include <stdio.h> 2 3 int main(){ 4 __int64 a; 5 __int64 b; 6 __int64 c; 7 8 while(scanf("%I64X%I64X",&a,&b)!=EOF){ 9 c=a+b;10 11 if(c<0){12 c=-c;13 printf("-");14 }15 printf("%I64X\n",c);16 }17 18 return 0;19 }
0 0
- A + B Again
- HDU A + B Again
- HDU_2057 A + B Again
- 4629. A+B Again
- 【2057 A + B Again ?】
- hdu2057 A + B Again
- hdoj2057 A+B Again
- 2057 A + B Again
- hdu2057 A + B Again
- A + B Again
- A + B Again
- hdoj A + B Again
- HDU2057 A + B Again
- A + B Again
- A+B Again
- hdu2057 A + B Again
- hdu2057 A + B Again
- HDU2057 A + B Again
- Android平台下基于XMPP的IM研究(二 MultiUserChat 聊天室)
- 博客感想-1
- 【.Net码农】huangxincheng一线码农系列--wcf系列学习5天速成
- MongoDB资料汇总专题
- 【LeetCode】【Solution】Maximum Product Subarray
- A + B Again
- web.xml配置详解
- matlab--颜色空间的转换
- 【转】C语言中#if #else 有什么作用?
- 机器学习之&&Andrew Ng课程复习--- 神经网络3
- 根据选择的日期字符串判断今天明天后天
- 如何进行Linux Kernel 开发
- 实现一个简单的手势解锁
- Android textview显示多行