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. ^_^
InputInput may contain multiple test cases. Each case contains A and B in one line.
If you can’t AC this problem, you would invite me for night meal. ^_^
A, B are hexadecimal number.
Input terminates by EOF.
OutputOutput A+B in decimal number in one line.Sample Input
1 9 A B a bSample Output
10 21 21
不认识题目里边的英文单词就很尴尬了。还有这个竟然只需要用%x,%d就可以.......,我转的转的已经把自己给转晕了,
等我有空再解决这个问题
正解
#include <stdio.h> int main(void) { int a, b; while(scanf("%x%x", &a, &b) != EOF) { printf("%d\n", a + b); } return 0; }错解
#include<stdio.h> #include<ctype.h> int convert(char x){ if(isdigit(x)) return x-'0'; else if(islower(x)) toupper(x); return x-'A'+10; } /*int convert(char x){ if(islower(x-'0')) toupper(x-'0'); if(x>='0'&&x<='9') return x-'0'; else if(x>='A'&&x<='F') return x-'A'+10; */ int main(void){ char a,b; while(scanf("%c%c",&a,&b)!=EOF){ printf("%d\n",convert(a)+convert(b)); } } #include<stdio.h> #include<ctype.h> int convert(char x){ if(islower(x-'0')) toupper(x-'0'); if(x>='0'&&x<='9') return x-'0'; else if(x>='A'&&x<='F') return x-'A'+10; }