1060 Are They Equal (25 point(s))
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.123×105 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.
Input Specification:
Each input file contains one test case which gives three numbers N, A and B, where N (<100) 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 10100, and that its total digit number is less than 100.
Output Specification:
For each test case, print in a line YES
if the two numbers are treated equal, and then the number in the standard form 0.d[1]...d[N]*10^k
(d[1]
>0 unless the number is 0); or NO
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.
Sample Input 1:
Sample Output 1:
Sample Input 2:
Sample Output 2:
经验总结:
这一题,难度还可以,就是细节的处理让人摸不着头脑,题目也没有任何提示,而且题目的测试集还不严谨.....很想跟他们反馈却根本找不到反馈的地方(遇到不严谨的地方不止一次了)
首先,说说这一题的不严谨的地方吧,对于最低限度不严谨的AC的代码,如果你输入 3 123 0.123 ,竟然可以得出 这两个浮点数是相等的结论..... 很明显,是没有判断指数是否相等。
然后,就是要注意这样一个样例 3 000002.0000001 2 这两个浮点数是相等的,就是注意前导0的处理。
最后,要注意0的处理,比如输出样例 3 0 000000.0000000,应该相等,输出的时候还要按照指定形式进行输出,输出应该为,YES 0.000*10*0
就这么多啦~
AC代码