HDU 2057 A + B Again 【16进制加法】
来源:互联网 发布:淘宝首页焦点图在哪里 编辑:程序博客网 时间:2024/04/29 20:34
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 !
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.
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 121A -9-1A -121A -AA
Sample Output
02C11-2C-90
思路:进制转换再做加减,较麻烦。所以直接%x吧,X输出大写字母,x输出小写字母..
AC代码:
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){ long long n, m, ans; while(~scanf("%llX%llX",&n,&m)) { ans = n + m; if(ans < 0) printf("-%llX\n",-ans); else printf("%llX\n",ans); } return 0;}
主要是头一次用这东西,所以记录下来吧,此时我想起了玲珑学院的一道8进制减法题,顺便贴一下,有时用这些输入输出是可以大大减少计算量的。
至于下面的8进制减法为什么要用unsigned int,是因为那道题卡数据了,用int会溢出..
AC代码:
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;int main(){ unsigned int a,b,n,ans; while(~scanf("%d",&n)) { while(n--) { scanf("%o%o",&a,&b); if(a < b) { swap(a, b); cout << "-"; } ans = a - b; printf("%o\n",ans); } } return 0;}
0 0
- HDU 2057 A + B Again 16进制加法
- HDU 2057 A + B Again(16进制加法)
- HDU 2057 A + B Again 【16进制加法】
- hdoj A + B Again 2057 (16进制加法)
- hdu 2057 A+B Again
- hdu 2057 A + B again
- HDU-2057A + B Again
- hdu 2057 A + B Again
- HDU 2057 A + B Again
- hdu-2057-A + B Again
- HDU 2057 A + B Again
- HDU 2057 A + B Again
- hdu 2057 A + B Again
- HDU 2057 A + B Again
- HDU - 2057 A + B Again
- hdu 2057 a + b again
- HDU-2057 A+B Again
- hdu 2057 A + B Again
- aqicn.org的秘密
- iOS中的三大定时器
- 线程与读写锁
- node.js学习日记——(7)
- 【JZOJ4964】【GDKOI2017模拟1.21】Rhyme
- HDU 2057 A + B Again 【16进制加法】
- vi编辑器常用功能
- 对std::vector/list的iterator简单包装尝试
- Spring_16_AOP 基础
- scala + intellij idea 环境搭建及编译、打包
- 猫和路由器和交换机的区别
- Lock和synchronized的区别
- 欢迎使用CSDN-markdown编辑器
- 背景图处理总结