A + B Again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19054 Accepted Submission(s): 8230
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 十六进制,可以用scanf直接输入,输出可以用printf直接输出,因为说的长度是小于15的,正好在longlong表示范围内,唉,刚开始还模拟了半天。#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { long long a,b,ans; while(~scanf("%I64X %I64X",&a,&b))///只是用十六进制输入,有正负 { ans=a+b;///直接相加 if(ans<0){printf("-");ans=-ans;}///因为输出是无符号的,防止输出补码的十六进制。 printf("%I64X\n",ans);///输出十六进制形式。 } return 0; }