A + B Again

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 15391 Accepted Submission(s): 6713

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

思路:当时写的时候,想的是把16进制转化为10进制,相加后再转化为16进制,感觉比较麻烦

就查了网上的博客,才发现16进制也可以加减,就是不能输出正负好,就设置了一个字符c来
控制正负,注意printf("%x\n",sum);和printf(“%X\n",sum);在这道题上是有区别的;刚开始就把
“X"写成"x",一直提交说答案错误!!!正确代码如下
#include<stdio.h>
int main()
{
__int64 a,b,sum;
char c;
while(scanf("%I64X %I64X",&a,&b)!=EOF)
{
sum=a+b;
if(sum<0)
{
sum=-sum;
c='-';
}
else
c=0;
if(c)
putchar(c);
printf("%I64X\n",sum);
}
return 0;
}

2057 A + B Again的更多相关文章

  1. 扩展欧几里德算法 cogs.tk 2057. [ZLXOI2015]殉国

    2057. [ZLXOI2015]殉国 ★☆   输入文件:BlackHawk.in   输出文件:BlackHawk.out   评测插件时间限制:0.05 s   内存限制:256 MB [题目描 ...

  2. hdu 2057 A+B

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2057 For each test case,print the sum of A and B in h ...

  3. hdu 2057 A+B Again

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2057 题目分析:涉及到16进制内的加法,可以用%I64x直接来处理,要注意到16进制中负数是用补码来表 ...

  4. HDU 2057 十六进制加减法

    http://acm.hdu.edu.cn/showproblem.php?pid=2057   水题,%I64X 长整形十六进制输入输出     #include<stdio.h> in ...

  5. AC日记——#2057. 「TJOI / HEOI2016」游戏 LOJ

    #2057. 「TJOI / HEOI2016」游戏 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include &l ...

  6. poj 2057 树形DP,数学期望

    题目链接:http://poj.org/problem?id=2057 题意:有一只蜗牛爬上树睡着之后从树上掉下来,发现后面的"房子"却丢在了树上面, 现在这只蜗牛要求寻找它的房子 ...

  7. 杭电oj2081、2091、1004、2057

    2081  手机短号 #include<stdio.h> #include<string.h> int main(){ int i,n; ]; while(scanf(&quo ...

  8. FZU 2057 家谱(dfs)

    Problem 2057 家谱 Accept: 129    Submit: 356Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem ...

  9. cogs 2057. [ZLXOI2015]殉国

    2057. [ZLXOI2015]殉国 ★☆   输入文件:BlackHawk.in   输出文件:BlackHawk.out   评测插件时间限制:0.05 s   内存限制:256 MB [题目描 ...

  10. 题解报告:hdu 2057 A + B Again

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2057 问题描述 我们的HDOJ必须有许多A + B问题,现在又有新的问题出现. 给你两个十六进制整数, ...

随机推荐

  1. UVa 1658 Admiral(最小费用最大流)

    拆点费用流 --------------------------------------------------------------------- #include<cstdio> # ...

  2. bind和live

    <div> <ul> <li></li> <li></li> <li></li> <li>& ...

  3. Symfony命令行

    Available commands:  help                                  显示命令的帮助信息  list                           ...

  4. mysql 组合索引

    MySQL单列索引是我们使用MySQL数据库中经常会见到的,MySQL单列索引和组合索引的区别可能有很多人还不是十分的了解,下面就为您分析两者的主要区别,供您参考学习. 为了形象地对比两者,再建一个表 ...

  5. 【转载】关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型

    1.#!/usr/bin/python 是用来说明脚本语言是 python 的 是要用 /usr/bin下面的程序(工具)python,这个解释器,来解释 python 脚本,来运行 python 脚 ...

  6. [LeetCode]题解(python):084-Largest Rectangle in Histogram

    题目来源: https://leetcode.com/problems/largest-rectangle-in-histogram/ 题意分析: 给定一个数组,数组的数字代表这个位置上的bar的高度 ...

  7. iOS 之播放系统声音

    导入框架: 代码: #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> @interface MsgPl ...

  8. WORD 无格式粘贴 2003 2007 MacOS2011

    2003 打开Word窗口,依次点击“工具----宏----Visual Basic编辑器”,打开“Microsoft visual Basic”窗口,在左侧“工程”栏选中“Normal”工程,点击“ ...

  9. jQuery json数据处理

    一种是使用jQuery的ajax函数  另一种是使用getJSON函数 使用ajax函数的时候 对于返回值类型dataType 亲自指定为json格式 就无需自己手动处理格式 $.ajax({ url ...

  10. 图中两点间路径为l的数目

    用矩阵G表示图的邻接阵. G2中的元素就是两点间路径为2的路径数,同理G3就是两点间路径为3的路径数目. 并且此结论同样适用于有向图. 甚至,此结论适用于有权图,只是算出来的不再是路径数,而是各条路径 ...