ACM
無聊到來寫看看ACM 結果錯超多
http://uva.onlinejudge.org/
很好的中譯題目
http://www.tcgs.tc.edu.tw/~sagit/luckycat/
新手寫 ACM 的注意事項
1. 不能 system("pause");
2. 嚴格的output格式
output:
1 2 3 4 5
//錯誤寫法(最後面多了一個空白)
for(i = 1; i <= 5; ++i){
cout << i << " ";
}
//正確寫法
for(i = 1; i < 5; ++i){
cout << i << " ";
}
cout << i;
3. 快速切換 input stream
每次 debug 就要打一次資料 打久了一定會崩潰
可以用 stringstream 的方式使用 ccin 取代 cin
但是正式上傳時又要改回 cin 很麻煩
他的線上判斷系統會自動 #define ONLINE_JUDGE
所以巨集是不錯的選擇,程式不用 ccin, cin 改來改去
#ifdef ONLINE_JUDGE
void Pause() {}
istream &ccin = cin;
#else
void Pause() { system("pause"); }
string testInput(){
string str;
str += "1 2 3\n";
str += "3 2 1\n";
str += "1 2 3 4 5 6 7\n";
str += "I am input data !!\n";
return str;
}
istringstream ccin(testInput());
#endif


0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁