本来应该是一个水题的,结果还是细节上有点小问题,之前WA的2次代码没有处理好中间0,例如输入502,应该输出205的,结果按之前的代码的话就直接给中间0那给截断了,只输出了一个两位数……所以肯定是WA了。之后注意了下中间0,就给AC了。
在这里也给出除了例题的另一组特殊数据吧,方便小伙伴们测试
input:
3
-0012560020
00000
00205
output:
-20065210
0
502
题目描述:Reverse Number(数字逆序)
Memory Limit: 65536/32768 K (Java/Others)
Problem Description
Welcome to 2006’4 computer college programming contest!
Specially, I give my best regards to all freshmen! You are the future of HDU ACM! And now, I must tell you that ACM problems are always not so easy, but, except this one… Ha-Ha!
Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows:
- The reverse number of a positive integer ending without 0 is general reverse, for example, reverse (12) = 21;
- The reverse number of a negative integer is negative, for example, reverse (-12) = -21;
- The reverse number of an integer ending with 0 is described as example, reverse (1200) = 2100.
Input
Input file contains multiple test cases. There is a positive integer n (n<100) in the first line, which means the number of test cases, and then n 32-bit integers follow.
Output
For each test case, you should output its reverse number, one case per line.
Sample Input
3
12
-12
1200
Sample Output
21
-21
2100
Author
Source
原题链接
More info:Question
Accepted代码
1 |
|
ps.直接用int感觉应该也可以过吧,题目里貌似是说了int32位的数,我的AC代码只是因为之前WA时误以为是数据类型的锅,就给改成了long long int,有兴趣的小伙伴可以试试直接跑int。
参考博客
感谢 cnxo 的 HDOJ 1266 Reverse Number(数字反向输出题) 提示了我之前WA考略欠缺的地方(不过貌似他给的数据输出有点不对?已给老哥评论了,等回复)
Author: Zoey
Link: https://zoey1038569979.github.io/2019/08/17/hdoj1266/
Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.