A + B Again HDU - 2057
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.
Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.
Easy ? AC it !
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 -AASample Output
0 2C 11 -2C -90
2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
//题意,多组输入,每组两个16进制数,输出16进制和
//%I64X :输出无符号十六进制数,用大写字母,也就是说%I64X的格式无法输出负数的
//所以对于结果是负数有单独处理
int main()
{
__int64 a,b,c;
while(~scanf("%I64X%I64X",&a,&b))
{
c=a+b;
if(c<0)
{
printf("-%I64X\n",-c);
}
else
printf("%I64X\n",c);
}
return 0;
}
//2018.5.31
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,s;
while(~scanf("%llX%llX",&a,&b))
{
s=a+b;
if(s<0)
printf("-%llX\n",-s);
else
printf("%llX\n",s);
}
return 0;
}