A+B Coming

3人阅读 评论(0) 收藏 举报
分类:

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. 
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 b
Sample 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;
}



查看评论

网络工程师CIDR技术强化训练教程

-
  • 1970年01月01日 08:00

【ACM解题报告】A+B Coming

Problem Description Many classmates said to me that A+B is must needs. If you can’t AC this problem,...
  • u012712087
  • u012712087
  • 2015-08-24 15:59:31
  • 934

A+B Coming(杭电ACM steps)(特意拿c语言写的。。。)

Problem Description: Many classmates said to me that A+B is must needs. If you can’t AC this pro...
  • Infinite8125
  • Infinite8125
  • 2015-01-25 21:48:20
  • 921

1.2.2 a+b coming

printf有读入16进制的功能%x #include #include using namespace std; int main(){ int a,b; while(scanf("%x...
  • GrimCake
  • GrimCake
  • 2017-02-25 22:56:22
  • 125

杭电 HDU ACM 1720 A+B Coming

 A+B Coming Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...
  • lsgqjh
  • lsgqjh
  • 2015-04-07 21:43:16
  • 862

HDU1720 A+B Coming]【十六进制】

A+B Coming Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot...
  • tigerisland45
  • tigerisland45
  • 2016-07-27 01:08:24
  • 809

hdoj-1720-A+B Coming

Problem Description Many classmates said to me that A+B is must needs. If you can’t AC this proble...
  • Ypopstar
  • Ypopstar
  • 2016-06-21 14:17:11
  • 258

HDU1720 A+B Coming

Problem Description Many classmates said to me that A+B is must needs. If you can’t AC this proble...
  • u011151784
  • u011151784
  • 2017-05-03 09:42:38
  • 378

HDU2057

A + B Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To...
  • zcj5027
  • zcj5027
  • 2016-01-23 14:51:48
  • 352

hd 1720 A+B Coming

#include int main() {     int n,m;     while(scanf("%x%x",&m,&n)!=EOF)     {      printf("%d\n...
  • lc311309010103
  • lc311309010103
  • 2014-07-29 15:45:45
  • 210
    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 564
    积分: 488
    排名: 10万+
    博客专栏
    文章存档
    最新评论