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. Structs

    1.服务端的运行程序 2.Servlet的三个方法 init service:抽象方法 destroy 3.步骤 (1).在web.xml中 <servlet> <servlet-n ...

  2. 利用python进行数据分析之pandas库的应用(二)

    本节介绍Series和DataFrame中的数据的基本手段 重新索引 pandas对象的一个重要方法就是reindex,作用是创建一个适应新索引的新对象 >>> from panda ...

  3. perl5 第六章 模式匹配

    第六章 模式匹配 by flamephoenix 一.简介二.匹配操作符三.模式中的特殊字符  1.字符+  2.字符 []和[^]  3.字符 *和?  4.转义字符  5.匹配任意字母或数字  6 ...

  4. 【剑指offer】面试题43:n个骰子的点数

    第一种思路是,每一个骰子的点数从最小到最大,如果为1-6,那么全部的骰子从最小1開始,我们如果一种从左向右的排列,右边的最低,索引从最低開始,推断和的情况. def setTo1(dices, sta ...

  5. redis研究笔记

    本文链接:http://blog.csdn.net/u012150179/article/details/38077851 一. redis Redis is an in-memory databas ...

  6. Razor强类型视图下的文件上传

    域模型Users.cs using System;using System.Collections.Generic;using System.Linq;using System.Web; namesp ...

  7. asp.net个人笔记

    1.进程外session一记 配置进程外session, 在webconfig中配置<sessionState timeout="60" mode="StateSe ...

  8. IOS中的自动布局

    Autolayout是一种“自动布局”技术,专门用来布局UI界面 Autolayout能很轻松地解决屏幕适配问题 Autolayout的两条核心概念:   >1 参照:通过参照其他控件或父控件来 ...

  9. Java之SPI机制

    之前开阿里的HSF框架,里面用到了Java的SPI机制,今天闲暇的时候去了解了一下,通过写博客来记录一下 SPI的全名为Service Provider Interface,我对于该机制的理解是为接口 ...

  10. CentOS7 安装JDK

    链接地址:http://jingyan.baidu.com/article/c74d60007b85510f6a595dfa.html VMware 10 centos 安装jdk 及mysql 方法 ...