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 !
 
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.
 
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,不能输出负数,所以负数的输出要做处理。

 #include <stdio.h>

 int main(){
__int64 a;
__int64 b;
__int64 c; while(scanf("%I64X%I64X",&a,&b)!=EOF){
c=a+b; if(c<){
c=-c;
printf("-");
}
printf("%I64X\n",c);
} return ;
}

随机推荐

  1. Cocos2d-x单机游戏防八门神器修改数据

    来源:http://cocos2d.9tech.cn/news/2014/0212/39812.html 网上的cocos2d-x教程多为知识点的讲解,但我们学习cocos2d-x的目的是为了什么?为 ...

  2. Linux top和负载的解释

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法. top - 01:06:48 up  1:22,   ...

  3. webconfig文件serviceHostingEnvironment节点出错的解决方法

    在三点五和二版本的配置中可以出现这个节点,但是在4.0是没有的,所以如果框架是4.0的时候要除去这个节点,不然就会报以下错误: Configuration Error Description: An ...

  4. 如何防止ASP.NET网站遭受CSRF的攻击

    转载地址: http://www.cnblogs.com/shanyou/p/5038794.html?hmsr=toutiao.io&utm_medium=toutiao.io&ut ...

  5. C#调用存储过程详解

    连接字符串: string conn = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].C ...

  6. Windows操作系统单文件夹下到底能存放多少文件及单文件的最大容量

    本文是转自:http://hi.baidu.com/aqgjoypubihoqxr/item/c896921f8c2eaba5feded5f2         最近需要了解Windows中单个文件夹下 ...

  7. Apache实现动态虚拟主机

    经常在开发中为Apache web server添加虚拟主机  方便多个项目的 同时运营,但是每次增加新的项目时都得重新配置增加VirtualHost:虚拟主机    部分,时间久了VirtualHo ...

  8. EXTJS中的grid显示实际行号

    添加一个新的功能 Ext.grid.PageRowNumberer = Ext.extend(Ext.grid.RowNumberer, { width : 40, renderer:function ...

  9. VPW Communication Protocol

    http://www.fastfieros.com/tech/vpw_communication_protocol.htm Breakdown of the j1850 3 byte Header f ...

  10. PostgreSQL的注释嵌套的例子

    pgsql=# -- Multiline comments pgsql=# SELECT 'Multi' /* This comment extends across pgsql*# * number ...