原题:
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 !
题意:
给出两个十六进制的数字,求它们两个的加和,用十六进制输出。
题解:
C语言直接有十六进制的输入符%I64x,(做题的时候刚查的,第一次用),然后也有十六进制的输出符,只不过稍微处理一下正负号的问题,因为十六进制直接输出不带负号。
代码:AC
#include<stdio.h>
int main()
{
__int64 a,b,c;
while(scanf("%I64x %I64x",&a,&b)!=EOF)
{
c=a+b;
if(c>=0)
printf("%I64X\n",c);
else
printf("-%I64X\n",-c);
}
return 0;
}