cf-tool github傳送門
第一步:cf-tool 下載
第二步:配置系統環境變量-教程,添加cf.exe所在目錄(用戶變量和系統變量都要添加)
第三步:win+R-輸入cmd-回車,打開命令行界面,輸入
cf config
配置cf-tool
(1)輸入0,登錄codeforces
(2)輸入1,添加代碼模板
①選擇模板語言
Language list:
14: ActiveTcl 8.5
33: Ada GNAT 4
18: Befunge
9: C# Mono 5.18
52: Clang++17 Diagnostics
28: D DMD32 v2.086.0
3: Delphi 7
39: FALSE
25: Factor
4: Free Pascal 3.0.2
45: GNU C++11 5 ZIP
42: GNU G++11 5.1.0
50: GNU G++14 6.4.0
54: GNU G++17 7.3.0
43: GNU GCC C11 5.1.0
32: Go 1.12.6
12: Haskell GHC 8.6.3
15: Io-2008-01-07 (Win32)
47: J
36: Java 1.8.0_162
60: Java 11.0.5
46: Java 8 ZIP
34: JavaScript V8 4.8.0
48: Kotlin 1.3.10
56: Microsoft Q#
2: Microsoft Visual C++ 2010
59: Microsoft Visual C++ 2017
38: Mysterious Language
55: Node.js 9.4.0
19: OCaml 4.02.1
22: OpenCobol 1.0
6: PHP 7.2.13
51: PascalABC.NET 3.4.2
13: Perl 5.20.1
44: Picat 0.9
17: Pike 7.8
40: PyPy 2.7 (7.2.0)
41: PyPy 3.6 (7.2.0)
7: Python 2.7.15
31: Python 3.7.2
27: Roco
8: Ruby 2.0.0p645
49: Rust 1.35.0
20: Scala 2.12.8
26: Secret_171
Select a language (e.g. "42"):
②
Template:
You can insert some placeholders into your template code. When generate a code from the
template, cf will replace all placeholders by following rules:
$%U%$ Handle (e.g. xalanq)
$%Y%$ Year (e.g. 2019)
$%M%$ Month (e.g. 04)
$%D%$ Day (e.g. 09)
$%h%$ Hour (e.g. 08)
$%m%$ Minute (e.g. 05)
$%s%$ Second (e.g. 00)
Template absolute path(e.g. "~/template/io.cpp"):
輸入模板代碼文件所在路徑,如 D:/a.cpp
③
The suffix of template above will be added by default.
Other suffix? (e.g. "cxx cc"), empty is ok:
此處是修改文件后綴名,可以直接回車跳過
④
Template's alias (e.g. "cpp" "py"):
此處是修改模板文件名,輸入想要的命名如 abc
⑤
Script in template:
Template will run 3 scripts in sequence when you run "cf test":
- before_script (execute once)
- script (execute the number of samples times)
- after_script (execute once)
You could set "before_script" or "after_script" to empty string, meaning not executing.
You have to run your program in "script" with standard input/output (no need to redirect).
You can insert some placeholders in your scripts. When execute a script,
cf will replace all placeholders by following rules:
$%path%$ Path to source file (Excluding $%full%$, e.g. "/home/xalanq/")
$%full%$ Full name of source file (e.g. "a.cpp")
$%file%$ Name of source file (Excluding suffix, e.g. "a")
$%rand%$ Random string with 8 character (including "a-z" "0-9")
Before script (e.g. "g++ $%full%$ -o $%file%$.exe -std=c++11"), empty is ok:
這里提供三個腳本命令
- before_script (execute once)
- script (execute the number of samples times)
- after_script (execute once)
如果想在打比賽時在CF tool中測試樣例,如下設置,達到自動編譯自動執行的效果:
首先輸入編譯指令,此處為C++的
g++ $%full%$ -o $%file%$.exe -std=c++11
然后輸入需要執行的exe文件路徑,
./$%file%$.exe
最后一步可用於刪除編譯生成的exe文件,可以直接回車跳過
然后詢問是否將這個模板設為默認模板,隨意選擇即可
(3)輸入4,開啟這個選項,可以在比賽時自動在相應文件夾下按模板生成cpp文件。
第四步:比賽使用
輸入以下命令進入相應的比賽,如cf race 1328。比賽id可從cf網站相應頁面的地址欄獲得。
cf race 比賽id
然后會載入比賽信息,如下圖:
可以直接在命令行界面編寫代碼,具體見官方說明,此處略過。
輸入以下指令 ,進入想要提交/測試的題目的相應目錄,以A題為例
cd C:\Users\18372\cf\contest\1328\a
輸入以下指令,對A題代碼進行樣例測試
cf test
*如果此處g++有報錯,請參考:windows下'g++'不是內部或外部命令 解決方法
返回結果如下圖:
注意:對不同題目的操作記得要先進入相應的文件夾再執行test、submit等指令
cf submit 提交
cf test 在當前目錄下執行模板里的命令,並測試全部樣例。如果你想加一組新的測試數據,
新建兩個文件 "inK.txt" 和 "ansK.txt" 即可,其中 K 是包含 0~9 的字符串。
cf list 列出當前比賽的題目通過、時限等情況
cf watch 查看自己在當前比賽的最后 10 次提交結果。
更多指令見官方說明