**题目:
Problem Description
Many classmates said to me that A+B is must needs.
If you can’t AC this problem, you would invite me for night meal. _
Input
Input may contain multiple test cases. Each case contains A and B in one line.
A, B are hexadecimal number.
Input terminates by EOF.
Output
Output A+B in decimal number in one line.
Sample Input
1 9
A B
a b
Sample Output
10
21
21**
代码:
#include<iostream>
using namespace std;
int main(){
int a,b;
while(cin>>hex>>a>>hex>>b){
cout<<a+b<<endl;
}
return 0;
}
代码:这一题其实很有技巧性,因为无论是A或者是a它们的十六进制转换成十进制都是10.所以这一题可以利用输入一个十六进制的数然后输出他们的十进制之和。这里值得注意的是定义a和b的时候都应该定义成整型(我当时定义成了字符型,因为我认识字符a和b都是属于字符),定义成整型就代表你输入进来的十六进制的数都会被整型转换成一个十进制的数,然后在输出求和。