A+B is coming

A+B is coming

  • 寒假在家准备刷一下杭电的OJ,开始2000~2011,入门级,感觉还好,就开始了英文的入门题,当时看见十六进制觉得不难,还是年轻啊。自己只注意了一位数字的加减,忽略了多位加,比如 1a+2b,所以wrong answer,开始不明白,百度,看见了直接用hex流输入,三四行就ok。

A+B Coming
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16659 Accepted Submission(s): 10548

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

Author
威士忌

Source
HZIEE 2007 Programming Contest

  • 开始的wrong
#include<bits/stdc++.h>
using namespace std;


int main()
{
    char a,b;int c,d;
    while(cin>>a>>b)

    {
         c=a-'0';
         d=b-'0';
    if((c>=0&&c<=9))
        c=c;
    else if(c>=17&&c<=22)
        c=c-7;
    else c=c-39;
    if((d>=0&&d<=9))
        d=d;
    else if(d>=17&&d<=22)
        d=d-7;
    else d=d-39;

    cout<<c+d<<endl;
    }




}

简单的accepted

#include<bits/stdc++.h>
using namespace std;


int main()
{
    int a,b;
    while(cin>>hex>>a>>hex>>b)
    {
        cout<<a+b<<endl;
    }



}


– 水平和大佬还是差距很大,继续吧,

发布了18 篇原创文章 · 获赞 0 · 访问量 271

猜你喜欢

转载自blog.csdn.net/qq_42815711/article/details/103809967
A+B