铂金组第三题

A + B Again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 37781 Accepted Submission(s): 15312

Problem Description

There must be many A + B problems in our HDOJ , now a new one is coming.
Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.
Easy ? AC it !

Input

The input contains several test cases, please process to the end of the file.
Each case consists of two hexadecimal integers A and B in a line seperated by a blank.
The length of A and B is less than 15.

Output

For each test case,print the sum of A and B in hexadecimal in one line.

Sample Input

+A -A
+1A 12
1A -9
-1A -12
1A -AA

Sample Output

0
2C
11
-2C
-90

问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2057
问题简述:输入两个十六进制的数,以十六进制输出它们的和
问题分析:注意以16进制输入并以16进制输出,字母大写,16进制数为负时,以补码形式输出。
程序分析:当C<0时,C=-C,输出‘-’和C;

#include<iomanip>
setiosflags(ios::uppercase)//输出大写字母
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    long long A, B,C;
    while (cin >> hex >> A >> B)
    {
        C = A + B;
        if (C < 0)
        {
            C = -C;
            cout <<"-"<< setiosflags(ios::uppercase)<<hex <<C ;
        }
        else
            cout << setiosflags(ios::uppercase) <<hex<< C;
        cout << endl;
    }
    return 0;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,161评论 0 10
  • 1."Error" 和 "Exception"之间有啥区别? error都是继承自父类java.lang.Erro...
    我要死掉了阅读 2,241评论 1 0
  • 1、AFNetworking 说明:网络请求库 下载地址:https://github.com/AFNetwork...
    段佳欢阅读 3,964评论 0 1
  • 晨起不见天日, 睡意尤其缱绻。 狠把衾被踢开。 冷遍四肢百骸。 忙把秋衣秋裤套身上。 蒸个鸡蛋馍馍。 洗把脸,漱个...
    江愚儿阅读 2,629评论 2 2