HDOJ 1002A + B Problem II求和问题(二)

版权声明:本文为博主原创文章,未经博主允许不得转载。http://blog.csdn.net/leytton https://blog.csdn.net/Leytton/article/details/79478558

0x00 前言

一看这道题,做大整数的加法,C语言中比较经典的题,没有几十行代码是解决不了的。不过用Java来写,里面有个BigInteger类专治这种牛皮藓,简直是分分钟搞定的送分题啊 <( ̄▽ ̄)> 哇哈哈…等下,提交的前两次显示Presentation Error 输出格式错误 这是什么鬼?查了下,一般是多了或者少了一些空格或者空行。好吧,继续改,不过AC结果有点出乎意料。。。
在线编程调试 http://www.dooccn.com/c/
Sum Problem II原题 http://acm.hdu.edu.cn/showproblem.php?pid=1002

0x01 题目

Sum Problem II
这道题要求输入整数T(1<=T<=20),接着输入T行测试案例,每行是两个大整数(每个长度范围不超过1000)。

0x02 错误格式1

注意使用Java编译器,要在Main类的main方法里写代码,记得引入包路径。

import java.math.BigInteger;
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int i=0;
        int T=cin.nextInt();
        while(++i<=T) {
            BigInteger a=cin.nextBigInteger();
            BigInteger b=cin.nextBigInteger();
            System.out.println("Case "+i+":\n"+a+" + "+b+" = "+a.add(b));
            if(i!=T) {
                System.out.println();
            }
        }
    }
}

测试输出:

Case 1:
1 + 2 = 3Case 2:┘
112233445566778899 + 998877665544332211 = 1111111111111111110

(此处表示回车)
提交代码,Presentation Error!回去审题,每个测试案例之间有换行、然后输出空行,最后一行不用输出空行。嗯,都满足要求,就开始猜测了,难道是最后一行不用换行?那么就有了下面的代码。

0x03 错误格式2

import java.math.BigInteger;
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int i=0;
        int T=cin.nextInt();
        while(++i<=T) {
            BigInteger a=cin.nextBigInteger();
            BigInteger b=cin.nextBigInteger();
            System.out.print("Case "+i+":\r\n"+a+" + "+b+" = "+a.add(b));
            if(i!=T) {
                System.out.println("\r\n");
            }
        }
    }
}

测试输出:

Case 1:
1 + 2 = 3Case 2:┘
112233445566778899 + 998877665544332211 = 1111111111111111110

这次的代码,最后一行少输出一个回车。还是Presentation Error
至于为什么某个槽点写法变了,完全是第一次手快第二次强迫症使然。开始还不相信,怀着半信半疑的态度买来。。哦不,提交试了下,效果杠杠的 ▄︻┻═┳一

0x04 最终AC代码

试了第三次才AC,大家一定没想到是这个的坑。。。

import java.math.BigInteger;
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int i=0;
        int T=cin.nextInt();
        while(++i<=T) {
            BigInteger a=cin.nextBigInteger();
            BigInteger b=cin.nextBigInteger();
            System.out.println("Case "+i+":\r\n"+a+" + "+b+" = "+a.add(b));
            if(i!=T) {
                System.out.println();
            }
        }
    }
}

嗯,你没看错\r\n\n 。。。冏rz

\n 为ASCII的0x0A 换行,进入下一行
\r 为ASCII的0x0D 回车,打印头回到行首上
Windows中,换行用\r\n表示,\r只回车不换行
Linux下换行用\n表示
更多资料参考
http://blog.csdn.net/yafeng_jiang/article/details/7103497
http://blog.csdn.net/stpeace/article/details/45767245

那么,我可以猜测HDOJ的Java编译器坐落在Windows系统里?( ̄︶ ̄)↗
看了下网页返回数据:
HDOJ系统
首页服务器采用的是Apache PHP/5.3.29,采用了squid/3.5.26缓存加速技术,难怪访问查询速度那么快,看来HD的小伙伴们是有用心优化过的。
看了下squid官网,基本是Linux版本,windows squid 3.x版本的还是开发版的,那么前端网站很有可能是Linux系统了。
至于编译器,完全可以采用单独服务器部署,没法准确判断系统。

【转载请注明出处: http://blog.csdn.net/leytton/article/details/79478558
PS:如果本文对您有帮助,请点个赞让我知道哦~微笑

猜你喜欢

转载自blog.csdn.net/Leytton/article/details/79478558