杭电 2053 java_(杭电 2053)A + B Again(转换说明符)

(杭电 2053)A + B Again(转换说明符)

TimeLimit:1000/1000MS(Java/Others)MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):39021AcceptedSubmission(s):15794

ProblemDescription

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

Foreach testcase,printthe sumofAandBinhexadecimalinone line.

SampleInput

+A-A

+1A12

1A-9

-1A-12

1A-AA

SampleOutput

02C11-2C-90

过年玩的有点嗨......emmmm....... 一开始打算用字符串储存之后一个个分析结果老是 WA...... 逛了一下讨论区看到了 dalao 们写的 ac 码 如下#include

intmain(void)

{

longlongi,a,b,sum;

while(scanf("%I64X %I64X",&a,&b)!=EOF)

{

sum=a+b;

if(sum>=0)

{

printf("%I64X\n",sum);

}

else

{

sum=-sum;

printf("-%I64X\n",sum);

}

}

}

发现了 %x 这个符号, 在论坛上找出一串相关符号

(以下转自网站)

转换说明符

%a(%A) 浮点数, 十六进制数字和 p-(P-)记数法(C99)

%c 字符

%d 有符号十进制整数

%f 浮点数(包括 float 和 doulbe)

%e(%E) 浮点数指数输出 [e-(E-) 记数法]

%g(%G) 浮点数不显无意义的零 "0"

%i 有符号十进制整数(与 %d 相同)

%u 无符号十进制整数

%o 八进制整数 e.g. 0123

%x(%X) 十六进制整数 0f(0F) e.g. 0x1234

%p 指针

%s 字符串

%% "%"

2` 标志

左对齐:"-" e.g. "%-20s"

右对齐:"+" e.g. "%+20s"

空格: 若符号为正, 则显示空格, 负则显示 "-" e.g. "% 6.2f"

#: 对 c,s,d,u 类无影响; 对 o 类, 在输出时加前缀 o; 对 x 类, 在输出时加前缀 0x;

对 e,g,f 类当结果有小数时才给出小数点.

3.格式字符串(格式)

〔标志〕〔输出最少宽度〕〔.精度〕〔长度〕类型

"%-md" : 左对齐, 若 m 比实际少时, 按实际输出.

"%m.ns": 输出 m 位, 取字符串(左起)n 位, 左补空格, 当 n>m or m 省略时 m=n

e.g. "%7.2s" 输入 CHINA

输出 "CH"

"%m.nf": 输出浮点数, m 为宽度, n 为小数点右边数位

e.g. "%3.1f" 输入 3852.99

输出 3853.0

来源: http://www.bubuko.com/infodetail-2950733.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值