***HDoj 2057 A + B Again

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
 

 

Author
linle
 

 

Source
 

 

Recommend
linle   |   We have carefully selected several similar problems for you:  2060 2058 2059 2061 2062 
 
 
C语言代码如下:
#include<stdio.h>
int main()
{
    __int64 a,b,sum;        //定义64位整型,注意开头是两个下划线连在一起
    while(scanf("%I64X%I64X",&a,&b)!=EOF)     //%x表示以是十六进制数形式输出整数(十六进制字母小写,%X是大写,也就是本题所用的),%I64x专门用来输出__int64类型
    {
        sum=a+b;
        if(sum<0)
            printf("-%I64X\n",-sum);          // %x是无符号的,不能输出负值,(所以输出前面要加个-)但是a,b这样的__int64变量可以为负值
                                                //用-sum是因为是二进制储存,所以当sum<0的时候如果直接输出会输出ffff所以换一种形式输出负号加sum的相反数,也就是sum的正值
        else
            printf("%I64X\n",sum);
    }
}

 

posted on 2020-04-15 22:26  沈香茶  阅读(181)  评论(0)    收藏  举报