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. javascriptDOM编程艺术_学习笔记_知识点 动态创建标记

    传统技术:document.write 和 innerHTML 深入剖析DOM方法:createElement.createTextNode.appendChild 和 insertBefore   ...

  2. 10条PHP编程习惯

    过去的几周对我来说是一段相当复杂的经历.我们公司进行了大裁员,我是其中之一,但却体验到了其中的乐 趣.我从来没有被开除过,所以很难不去想得太多.我开始浏览招聘板块,一个全职PHP程序员的职位很吸引人, ...

  3. PHP学习笔记5-类的继承/方法重写

    更改Man.php文件名为People.php,加入代码: public function hi(){ return $this->_name.' say hi'; } 新建文件Man.php: ...

  4. 一个帝国cms [!--show.listpage--] css样式

    1.在分页位置加<div class="pagepage">[!--show.listpage--]</div> </div>这个标签 2.在需 ...

  5. C#获取桌面壁纸图片的路径(Desktop Wallpaper)

    原文 C#获取桌面壁纸图片的路径(Desktop Wallpaper) 利用 Windows 的 API 获取桌面壁纸的实际路径,使用的是 SystemParametersInfo 这个API,此AP ...

  6. cocos2dx中的精灵CCSprite

    什么是精灵(CCSprite),在官网文档中是这么定义的 Sprites A cocos2d CCSprite is similar to sprites you find in other game ...

  7. SSH框架的简单学习—Structs学习

    一:struts部分 1.打开Myeclipse,创建一个web project,项目名称为SSHDemo. 2.在web的lib下粘贴struts2-blank.war解压后WEB-INF\lib下 ...

  8. Android测试TestSuite的执行方法

    public class StartTest extends InstrumentationTestRunner {         public  TestSuite getAllTests() { ...

  9. Failed to upgrade Oracle Cluster Registry configuration(root.sh)

        近期在给客户基于Suse 11 sp3安装Oracle 10g RAC,在安装完clusterware运行/u01/app/crs/root.sh时收到错误提示.Failed to upgra ...

  10. hql中不能写count(1)能够写count(a.id)

    hql中不能写count(1)能够写count(a.id)里面写详细的属性 String hql="select new com.haiyisoft.vo.entity.cc.repo.Bu ...