HDU2057 A + B Again【水题】

A + B Again

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


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
 

Author
linle
 

Source

问题链接HDU2057 A + B Again

问题分析

  投机取巧,按照许多人的做法来做,程序是AC了。即便如此,也是一脸困惑,不知道解了这种题意义何在?因为定义变量的类型是__int64,十分的不满意。还是希望用long long定义变量,但是输入输出格式。

  看一下下表,可以知道__int64 与long long 的区别。

变量定义输出方式gcc(mingw32)g++(mingw32)gcc(linux i386)g++(linux i386)MicrosoftVisual C++ 6.0
long long“%lld”错误错误正确正确无法编译
long long“%I64d”正确正确错误错误无法编译
__int64“lld”错误错误无法编译无法编译错误
__int64“%I64d”正确正确无法编译无法编译正确
long longcout非C++正确非C++正确无法编译
__int64cout非C++正确非C++无法编译无法编译
long longprintint64()正确正确正确正确无法编译

  计算机语言如果不标准,累死程序员。C99标准已经有了long long类型,使用该类型才是正解。

  从批判中学习,付出高昂学费得到的是教训,不是正确的途径,是在浪费时间。

  后来,经过一番研究,终于搞定了正解程序。那里需要注意的是,输出变量的时候,要用“%llX”,不要用“%llx”。这二者之间有微妙的差异。

程序说明


AC的C语言程序如下(正解):

/* HDU2057 A + B Again */

#include <stdio.h>

int main(void)
{
    long long a, b, result;

    while(scanf("%llx %llx", &a, &b) != EOF) {
        result = a + b;

        if (result >= 0)
            printf("%llX\n", result);
        else
            printf("-%llX\n", -result);
    }

    return 0;
}


另外一个AC的C语言程序如下(不满意的程序):

/* HDU2057 A + B Again */

#include <stdio.h>

int main(void)
{
    __int64 a, b, result;

    while(scanf("%I64X %I64X", &a, &b) != EOF) {
        result = a + b;

        if (result >= 0)
            printf("%I64X\n", result);
        else
            printf("-%I64X\n", -result);
    }

    return 0;
}



  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值