一看這道題,作大整數的加法,C語言中比較經典的題,沒有幾十行代碼是解決不了的。不過用Java來寫,裏面有個BigInteger類專治這種牛皮蘚,簡直是分分鐘搞定的送分題啊 <( ̄▽ ̄)> 哇哈哈…等下,提交的前兩次顯示Presentation Error
輸出格式錯誤
這是什麼鬼?查了下,通常是多了或者少了一些空格或者空行。好吧,繼續改,不過AC結果有點出乎意料。。。
在線編程調試 http://www.dooccn.com/c/
Sum Problem II原題 http://acm.hdu.edu.cn/showproblem.php?pid=1002php
這道題要求輸入整數T(1<=T<=20)
,接着輸入T
行測試案例,每行是兩個大整數(每一個長度範圍不超過1000)。css
注意使用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();
}
}
}
}
測試輸出:java
Case 1:
1 + 2 = 3┘
Case 2:┘
112233445566778899 + 998877665544332211 = 1111111111111111110┘
(此處┘
表示回車)
提交代碼,Presentation Error!回去審題,每一個測試案例之間有換行、而後輸出空行,最後一行不用輸出空行。嗯,都知足要求,就開始猜想了,難道是最後一行不用換行?那麼就有了下面的代碼。編程
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");
}
}
}
}
測試輸出:windows
Case 1:
1 + 2 = 3┘
Case 2:┘
112233445566778899 + 998877665544332211 = 1111111111111111110
此次的代碼,最後一行少輸出一個回車。仍是Presentation Error
!
至於爲何某個槽點寫法變了,徹底是第一次手快第二次強迫症使然。開始還不相信,懷着半信半疑的態度買來。。哦不,提交試了下,效果槓槓的 ▄︻┻═┳一緩存
試了第三次才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
。。。冏rzmarkdown
\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系統裏?( ̄︶ ̄)↗
看了下網頁返回數據:
首頁服務器採用的是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:若是本文對您有幫助,請點個贊讓我知道哦~