zoukankan      html  css  js  c++  java
  • (杭电2053)A + B Again(转换说明符)

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 39021 Accepted Submission(s): 15794

    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
    

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

    #include <stdio.h>
    
    int main(void)
    {
    	long long i,a,b,sum;
    
    	while(scanf("%I64X %I64X",&a,&b) != EOF)
    	{
    		sum = a+b;
    		if(sum >= 0)
    		{
    			printf("%I64X
    ",sum);
    		}
    		else
    		{
    			sum = -sum;
    			printf("-%I64X
    ",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

  • 相关阅读:
    SpringBoot 系列教程 web 篇之自定义请求匹配条件 RequestCondition
    SpringBoot 系列教程 JPA 错误姿势之环境配置问题
    react中constructor()和super()的具体含义以及如何使用
    原生js之canvas时钟组件
    js求和运算在可变参数的情况下ES3、ES5和ES6的写法区别
    好用的jquery.animateNumber.js数字动画插件
    sublime text3中设置Emmet输入标签自动闭合
    原生js移动端列表无缝间歇向上滚动
    原生js实现preAll和nextAll方法
    基于SwiperJs的H5/移动端下拉刷新上拉加载更多
  • 原文地址:https://www.cnblogs.com/cafu-chino/p/10363306.html
Copyright © 2011-2022 走看看