# OJ 使用手冊 ## Online Judge 的運作原理 裁判系統會以數量不一的測試資料去測試您所送出的程式碼來判定您的程式是否完全正確,若通過所有的測試資料的測驗,則系統認定您的程式碼為通過,否則將會呈現不同原因的結果,如 WA, TLE, MLE, OLE, CE, RE...等([裁判訊息](#裁判訊息))。 若沒有額外宣告中止條件,該題目會被視為連續輸入。此類題目必須在程式中放入一個 while 迴圈來讀取所有的測試資料,詳細範例請參照[連續輸入(EOF)範例](#連續輸入EOF範例)。 ## 程式碼撰寫注意事項 1. 請不要使用``system("pause");``之類的程式碼,否則會導致RE。 2. 連續輸入請根據題目的終止條件設計流程控制,否則會導致TLE。([終止條件列表](#終止條件列表補充)) 3. 請根據題目的Sample Output格式輸出(包含空格、換行、逗號等等),否則會導致WA, OLE。 4. 若在編寫過程中發生無法編譯狀況,請確認該題是否有執行檔正在執行。 5. 根據使用者回報,使用``do {} while();``格式的寫法會導致RE,請嘗試改用其他寫法。 6. 若發生以下問題,請先執行[此修正檔](https://drive.google.com/file/d/1owwAW8U9ex_7ZU6ZVgAqOjK8dNyt_IFk/view?usp=sharing)後將Visual Studio重開。  7. Visual Studio會預先引入一些函式庫(但OJ不會引入),請務必自行再添加一次([Visual Studio 預先載入library](#Visual-Studio-預先載入library)) 8. 出現RE: Segmentation fault,請檢查是否有以下情況 - 變數存取錯誤位置(超出陣列長度或是指標未定義) - (20200409)在函式內宣告的區域變數,將它的位址當成回傳值傳回 9. (20200326)若你的程式輸出了不可視字元,例如ascii編號小於0或是控制字元(下方ascii表中紅色全部大寫的部份),會造成以下兩種狀況,請嘗試避免之。 - 錯誤訊息顯示二進位檔案比較 - 錯誤訊息完全空白 10. (20200415)遇到檔案輸入的題目,由於OJ有鎖定寫入權限,請使用以下兩種方式讀檔。 - ``fstream f; f.open("filename.txt", "ios::in");`` - ``ifstream f;``  11. (20200503)若在編譯期間發生LNK1104錯誤,請依循下列步驟處理。 - 儲存所有檔案並關閉Visual Studio - 開啟新的Visual Studio,重新抓取專案(目標資料夾請重新新增) - 從原本專案的複製原始碼(.h, .cpp)至新的專案 11. (20200613)上述方法更新如下 - 儲存所有檔案並關閉Visual Studio - 對該資料夾複製貼上,使其資料夾名稱與原來的不同 - 至新資料夾開啟專案 12. (20200503)不要連續點擊上傳按鈕,以免造成重複上傳。 ## 裁判訊息 | Code | Full Name | 說明 | |-----:|-----------|-----| | <font color="green">AC</font> | Accept | 通過 | | <font color="red">WA</font> | Wrong Answer | 答案錯誤 | | <font color="red">FE</font> | Format Error | 程式輸出內容正確,但格式錯誤 | | <font color="red">TLE</font> | Time Limit Exceed | 執行超過時間限制 | | <font color="red">MLE</font> | Memory Limit Exceed | 程式超過記憶體限制 | | <font color="red">OLE</font> | Output Limit Exceed | 程式輸出超過預期行數 | | <font color="red">RE</font> | Runtime Error | 執行時錯誤 | | <font color="red">CE</font> | Compile Error | 編譯錯誤 | ## 連續輸入(EOF)範例 本範例為示範連續輸入程式之原始碼以及輸入輸出範例。 ### A + B 程式原始碼(main.cpp) ```cpp #include <iostream> using namespace std; int main(){ int a,b; while(cin >> a >> b) cout << a+b << endl; return 0; } ``` 將以上程式編譯成執行檔(main.exe)後,可以在命令提示字元(cmd)進行以下操作。此方法稱為標準輸入輸出轉送。 ```bat $ main.exe < input.txt > output.txt ``` 若直接執行main.exe,可以透過``Ctrl + Z``模擬EOF輸入。此時螢幕會出現``^Z``,按下Enter即可跳出程式。 ```bat $ main.exe 1 2 3 3 4 7 5 6 11 7 8 15 ^Z $ ``` ### A + B 程式標準輸入範例(input.txt) ```text 1 2 3 4 5 6 7 8 ``` ### A + B 程式標準輸出範例(output.txt) ```text 3 7 11 15 ``` ## 本地專案編譯注意事項 一個競賽會有多個題目,預設起始專案會在第一題。若要編譯其他題目的話,請依據以下步驟進行切換。 1. 對該專案點擊右鍵 2. 選擇「設定為啟始專案」(英文版為:"Set as StartUp Project")  ## 提交程式碼注意事項 以下步驟為理想提交程式碼的基本步驟,能降低交錯題目的困擾。 1. 對該專案點擊右鍵 2. 選擇「Upload and Judge」  ## 終止條件列表(補充) | 關鍵字 | 說明 | |-------|-----| | EOF | 連續輸入,以檔尾(EOF)結束 | | Keyword | 輸入一關鍵字(Exit, Quit)結束 | | n + 1 Lines | 第一行會宣告接下來有多少行要處理,會搭配EOF出現 | | 0 End | 連續輸入,輸入一至多個0結束 | | Line End | 單行多筆輸入,以\n結束 | Ref: [[ACM-ICPC] 淺談 I/O](https://blog.kuoe0.tw/posts/2013/02/22/acm-icpc-about-io/) ## Visual Studio 預先載入library 下列library為Visual Studio在編譯前會載入的的函式庫,這些在其他平台(例如OJ)並不會出現,請自行補上。 ```cpp #include <cerrno> // https://en.cppreference.com/w/cpp/header/cerrno #include <cfloat> // https://en.cppreference.com/w/cpp/header/cfloat #include <climits> // https://en.cppreference.com/w/cpp/header/climits #include <cmath> // https://en.cppreference.com/w/cpp/header/cmath #include <cstddef> // https://en.cppreference.com/w/cpp/header/cstddef #include <cstdint> // https://en.cppreference.com/w/cpp/header/cstdint #include <cstdio> // https://en.cppreference.com/w/cpp/header/cstdio #include <cstdlib> // https://en.cppreference.com/w/cpp/header/cstdlib #include <cstring> // https://en.cppreference.com/w/cpp/header/cstring #include <cwchar> // https://en.cppreference.com/w/cpp/header/cwchar #include <exception> // https://en.cppreference.com/w/cpp/header/exception #include <initializer_list> // https://en.cppreference.com/w/cpp/header/initializer_list #include <ios> // https://en.cppreference.com/w/cpp/header/ios #include <iosfwd> // https://en.cppreference.com/w/cpp/header/iosfwd #include <iostream> // https://en.cppreference.com/w/cpp/header/iostream #include <istream> // https://en.cppreference.com/w/cpp/header/istream #include <limits> // https://en.cppreference.com/w/cpp/header/limits #include <memory> // https://en.cppreference.com/w/cpp/header/memory #include <new> // https://en.cppreference.com/w/cpp/header/new #include <ostream> // https://en.cppreference.com/w/cpp/header/ostream #include <stdexcept> // https://en.cppreference.com/w/cpp/header/stdexcept #include <streambuf> // https://en.cppreference.com/w/cpp/header/streambuf #include <system_error> // https://en.cppreference.com/w/cpp/header/system_error #include <type_traits> // https://en.cppreference.com/w/cpp/header/type_traits #include <typeinfo> // https://en.cppreference.com/w/cpp/header/typeinfo #include <utility> // https://en.cppreference.com/w/cpp/header/utility // The following are the microsoft vc++ for stl library // Ref: https://github.com/microsoft/STL #include <xfacet> #include <xiosbase> #include <xlocale> #include <xlocinfo> #include <xmemory> #include <xmemory0> #include <xstddef> #include <xstring> #include <xtr1common> #include <xutility> ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up