Try   HackMD

外傳:關於 CP Editor 更多便利功能

關於設定

OptionsPreferences 或者輸入 CTRL+P 都能開啟設定畫面。

設定編譯選項

LanguageC++C++ Commands 可以設定編譯時的編譯器指令。理解前可以先忽略。

需要 C++11 時可在這裡加入 -std=c++11。例如:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

設定編輯器相關

LanguageC++C++ Snippets 可設定程式碼的樣板。不同於其它 IDE 常見的新檔案預設程式碼,CP Editor 是嵌入一段程式碼。

比較接近函式庫的概念,不過競程只能上傳單一檔案,因此採用直接嵌入的方式。

LanguageC++C++ Parentheses 可調整與括號相關的設定,像作者一樣覺得自動補完下括號很煩的話,可在這裡關掉它。

便利的 Competitive Companion

不用再自己複製範例測試資料、複製題目 ID 作為檔名,Competitive Companion 幫你一鍵搞定!

Competitive Companion 可在支援的 Online Judge(國外主流 OJ 大多支援,但國內的大多不支援)題目頁面,解析網頁內容後,將題號、範例的測試資料內容等打包傳遞給需要的程式。CP Editor 可以接收這些打包後的資料,自動建立新檔案,並將範例測試資料加入右下的測試資料中。

ExtensionsCompetitive Companion 可將此功能打開,可和 chrome extension 的 competitive companion 互動。

Competitive Companion 載點:https://chrome.google.com/webstore/detail/competitive-companion/cjnmckjndlpiamhfimnnjmnckgghkjbl

以 Kattis 舉例,原本題目頁面會有幾筆測試資料作為參考,並且做初步的驗證用,如下圖:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

原本要自己複製過去,但 competitive companion 可一鍵自動解析後,將資料傳給 CP Editor,就不需要自己複製,非常方便。

可惜的是,由於台灣產的 Online Judge 們沒有紅到國外,因此 competitive companion 並不支援。

注意:UVa 雖有被支援,但必須在原網站上使用,不能在 Lucky 貓或 ZJ 等網站,或者本講義提供的 UVa 題目連結使用。

另,目前(2022/08/29)分析出來的輸出和輸入皆會在最前面有個多餘的空白行。

其它

Asset 不同選項間的差別

有興趣了解差別再閱讀就行。需要一些電腦相關知識。

  • x64 v.s. x86
    64
    位元作業系統選前者,
    32
    位元作業系統選後者。現在
    32
    位元系統已很少見了,不知道怎麼選時就選 x64,除非電腦超級超級舊。
  • portable v.s. setup:前者是可攜版,不需要安裝也能使用,公用電腦等沒有安裝軟體的權限時也沒問題,但需要額外設定。後者是安裝版,如果是自己電腦,安裝比較方便。
  • with gcc and LLVM v.s. :前者自帶編譯器,後者沒有。當你想用自己喜歡的編譯器時的上級者選項。如果自己沒有編譯器或不會設定,選擇後者將無法執行程式

portable 版編譯器設定

如果選擇 portable 版本,需自行設定負責編譯用的「編譯器」所在位置。

  • 找到 CP Editor 解壓縮後的資料夾內,進入名為 mingw64 的資料夾。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 進入名為 bin 的資料夾。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 確認有個名為 c++ 的檔案。如果有設定顯示副檔名,會是 c++.exe
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 此時視窗上方會有顯示現在資料夾位置的地方,視解壓縮位置不同,可能和附圖不一樣。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 在顯示位置的地方,bin 的更後面的空白位置,點一下滑鼠左鍵,會顯示實際路徑,複製下來;以下圖為例,會是 D:\Download\cpeditor\mingw64\bin(請不要照抄,每人狀況不同)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 在 CP Editor 從功能表找到 OptionsPreferences 開啟設定視窗,找到 LanguageC++C++ Commands
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • C++ Compile Commandc++ 前面加入上面複製的路徑,用 \\ 來隔開路徑和 c++,再用雙引號把路徑開始到 c++ 為止包起來
    • 例如上例,原本是 c++ -Wall 就改成 "D:\\Download\\cpeditor\\mingw64\\bin\\c++" -Wall(請不要照抄,每人狀況不同)
  • 在最後面補上一個空白隔開後,加入 -static
    • 例如上例,最後會變成 "D:\\Download\\cpeditor\\mingw64\\bin\\c++" -Wall -static(請不要照抄,每人狀況不同)

如果操作正確,應該就能正常編譯了。

Loading embed note

tags: 競程:外傳, 競程