A+B Coming

来源:互联网 发布:程序员才能看懂的密码 编辑:程序博客网 时间:2024/05/16 11:24

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 9A Ba b
 

Sample Output

102121
 

主要是strtol函数的运用,它可以将字符串里面的数字传换成10进制。

#include<stdio.h>#include <stdlib.h>int main(){char a[16],b[16];long long x,y,sum;while(scanf("%s%s",&a,&b)!=EOF){ x=strtol( a,NULL,16);      y=strtol( b, NULL,16);  sum=x+y; if(sum<0){ sum=-sum; printf("-%d\n",sum);} else  printf("%d\n",sum);  }}

原创粉丝点击