1060 Are They Equal (25 分)
If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0 with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are supposed to tell if they are treated equal in that machine.
Each input file contains one test case which gives three numbers N, A and B, where N (<) is the number of significant digits, and A and B are the two float numbers to be compared. Each float number is non-negative, no greater than 1, and that its total digit number is less than 100.
For each test case, print in a line <code>YES</code> if the two numbers are treated equal, and then the number in the standard form <code>0.d[1]...d[N]*10^k</code> (<code>d[1]</code>>0 unless the number is 0); or <code>NO</code> if they are not treated equal, and then the two numbers in their standard form. All the terms must be separated by a space, with no extra space at the end of a line.
Note: Simple chopping is assumed without rounding.
题意:
给出两个数,问:将他们写成保留N (<100)位小数的科学计数法 <code>0.d[1]...d[N]*10^k</code> (<code>d[1]</code>>0 unless the number is 0); 后,是否相同。若相等,输出YES,并转换结果; 如果不相等,输出NO,并给出两个数的转换结果。
题解:
本题的思路难想而且情况判断非常复杂。
题目要求科学计数法时,两个数是否相等。因此只要判断科学技术法时的本体部分以及指数部分是否相等即可。
对于数据来说,要分为大于 1 与小于 1 来判断,要考虑各种情况下的数字,比如:0000, 000.00, 00123.4, 0.012, 0.00 等
一开始没有考虑太多的异常情况,拿了19分,第二天看了题解的注意点重做,还是只有21分,
第三天理了理思路,其实,只要关注,格式化好后的小数点要点在哪里,次数是多少就可以了,在此基础上,特判0,去掉前导零。比较的时候注意不要超限,输出不够0补齐。
自己编的测试样例:
AC代码: