税码检查,有什么问题,有什么区别?

 收藏

please help me with the following code. The code itself is from UriOnlineJudge(https://www.urionlinejudge.com.br/judge/en/problems/view/1051), but after many hours spent trying to figure out the problem i had to resolve to this site. First one is this:



            double sal = 0.0, t8 = 0.0, t18 = 0.0, t28 = 0.0;
            sal = double.Parse(Console.ReadLine());
            if(sal <= 2000.0)
            {
                Console.WriteLine("Isento");
            }else if( 2000.0 < sal && sal <= 3000.0)
            {
                t8 = ((sal - 2000.00) * 0.08);
                Console.WriteLine("R$ " + String.Format("{0:F2}", t8));
            } else if (3000.0 < sal && sal <= 4500.0)
            {
                t18 = ((sal - 3000.00) * 0.18 + 1000.00 * 0.08);
                Console.WriteLine("R$ " + String.Format("{0:F2}", t18));
            }
            else
            {
                t28 = ((sal - 4500.00) * 0.28 + 1500.00 * 0.18 + 1000.00 * 0.08);
                Console.WriteLine("R$ " + String.Format("{0:F2}", t28));
            }
           Console.ReadLine();

经过数小时的思考,我决定将其“更清洁”(减少线条),然后像这样重新进行修改,并且效果惊人,但是我仍然不明白为什么会这样,对我来说它们是相同的 第二个是这样的:


    double sal = 0.0, t8 = 0.0, t18 = 0.0, t28 = 0.0;
            sal = double.Parse(Console.ReadLine());
            if(sal <= 2000.0)
            {
                Console.WriteLine("Isento");
            }else if( 2000.0 < sal && sal <= 3000.0)
            {
                sal = sal - 2000.0;
                t8 = sal * 8.0 / 100.0;
                t8 = sal + t8;
                Console.WriteLine("R$ " + String.Format("{0:0.00}", t8));
            } else if (3000.0 < sal && sal <= 4500.0)
            {
                sal = sal - 3000.0;
                t8 = 1000.0 * 8.0 / 100.0;
                t18 = sal;
                t18 = t18 * 18.0 / 100.0;
                t18 = t18 + t8;
                Console.WriteLine("R$ " + String.Format("{0:0.00}", t18));
            }
            else
            {
                sal = sal - 4500.0;
                t8 = 1000.0 * 8.0 / 100.0;
                t18 = 1500.0 * 18.0 / 100.0;
                t28 = sal;
                t28 = t28 * 28.0 / 100.0;
                t28 = t28 + t18 + t8;
                Console.WriteLine("R$ " + String.Format("{0:0.00}", t28));
            }
           Console.ReadLine();

现在,我一直来回测试它们,它们显示出相同的结果,但是先生。 Uri的编译器不断向我显示第二个代码仍然有5%的错误,请您帮助我查找我的方法中的错误。

回复