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代碼: