HDOJ 2057 A + B Again

简介: HDOJ 2057 A + B Again

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

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            long str1 = sc.nextLong(16);
            long str2 = sc.nextLong(16);
            long a = str1+str2;
            if(a<0){
                //System.out.println(a);
                a=-a;
                //System.out.println(a);
                System.out.println("-"+Long.toHexString(a).toUpperCase());
            }else{
                System.out.println(Long.toHexString(a).toUpperCase());
            }
        }
    }
}
目录
相关文章
HDOJ 2041 超级楼梯
HDOJ 2041 超级楼梯
101 0
HDOJ 2056 Rectangles
HDOJ 2056 Rectangles
128 0
HDOJ 2013 蟠桃记
HDOJ 2013 蟠桃记
93 0
HDOJ 2004 成绩转换
HDOJ 2004 成绩转换
88 0
|
测试技术
HDOJ 2033 人见人爱A+B
Problem Description HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱。
956 0
HDOJ 2013 蟠桃记
Problem Description 喜欢西游记的同学肯定都知道悟空偷吃蟠桃的故事,你们一定都觉得这猴子太闹腾了,其实你们是有所不知:悟空是在研究一个数学问题! 什么问题?他研究的问题是蟠桃一共有多少个! 不过,到最后,他还是没能解决这个难题,呵呵^-^ 当时的情况是这样的: 第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩下的一半多一个,到第n天准备吃的时候只剩下一个桃子。
1074 0
|
测试技术
HDOJ 1232
畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15688 Accepted Submission(s): 8050 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。
812 0