HDU2057

作者: 费曼JW | 来源:发表于2019-06-13 16:39 被阅读0次

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2057

    思路:
    这道题的意思是两个十六进制数相加,输出结果任为十六进制。
    十六进制数的负数在输出时是使用补码的形式输出的,要加以转换。
    因为两个相加的数的长度小于15位,使用long long型储存。

    代码:

    #include <iostream>
    #include<iomanip>
    using namespace std;
    
    int main()
    {
        long long a,b;
        while(cin>>hex>>a>>hex>>b)
        {
            a+b<0?cout<<"-"<<setiosflags(ios::uppercase)<<hex<<-(a+b)<<endl:cout<<setiosflags(ios::uppercase)<<hex<<a+b<<endl;
        }
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:HDU2057

          本文链接:https://www.haomeiwen.com/subject/euisfctx.html