cf tool 使用指南

upd: 2025.02.01 重构文章。

现在由于 Codeforces 开启了 Cloudflare,所以相当多的命令无法使用,例如登录,提交,拉取等。

下载

下载地址:https://github.com/xalanq/cf-tool/releases/tag/v1.0.0

这个是 xalanq 的原版,有时候有一定 bug,我用过的比较好的另一个版本是 woshiluo 的,可以在这个仓库的 issue 里面找一下。

下载对应版本的压缩包即可。

配置

开始

首先,将下载的文件放入一个系统路径。

登录用户(不可用)

打开终端,然后键入以下内容

cf config

会跳出来这个东西:

Configure the tool
0) login
1) add a template
2) delete a template
3) set default template
4) run "cf gen" after "cf parse"
5) set host domain
6) set proxy
7) set folders' name
Please choose one (index):

输入 0 就行了。

Configure handle/email and password
Note: The password is invisible, just type it correctly.
handle/email:

出现了这段内容,你只需要输入你的用户名和密码,密码是不显示的,只需要键入它就行了,然后你就登陆成功了。

Succeed!!
Welcome ...~

配置代码模板

再次键入

cf config

接下来键入 1。

Add a template
Language list:
   14: ActiveTcl 8.5
...
   20: Scala 2.12.8
   26: Secret_171
Select a language (e.g. "42"):

这一段是让我们选择代码语言,建议选择代码语言之前先去 Codeforces 查询一下哪些语言现在还是可用的,比如 C++ 17 现在还是可以选的。

GNU G++14 6.4.0
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:\code\template.cpp

The suffix of template above will be added by default.
Other suffix? (e.g. "cxx cc"), empty is ok:

对于模板的后缀,直接键入 cpp 即可。

Template's alias (e.g. "cpp" "py"):

模板的名称,我们随便填一个,如 C++ Template

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:

这一段是要你填编译指令,直接键入 g++ $%full%$ -o $%file%$.exe -std=c++14

Script (e.g. "./$%file%$.exe" "python3 $%full%$"):

这一段是运行指令,输入 ./$%file%$.exe

After script (e.g. "rm $%file%$.exe" or "cmd.exe /C del $%file%$.exe" in windows), empty is ok:

这一段是删除可执行文件,我没有填,如果有需要可以填 rm $%file%$.exe

Make it default (y/n)?

是否要将它设为默认?填 y 就行了。

设置文件夹名称

继续输入

cf config

这次我们输入 7。

Set folders' name
Enter empty line if you don't want to change the value
Root path (current: cf)
> codeforces
contest path (current: contest)
> contest
gym path (current: gym)
> gym
group path (current: group)
> group
acmsguru path (current: acmsguru)
> acmsguru

完成。

接下来你如果在 D:\ 这个位置输入 cf race 1,那么文件就会保存在 D:\codeforces\contest\1\ 中。

基本使用

打开比赛(不可用)

我们可以用 cf tool 打开一场比赛。

如果这场比赛已经开始,那么他会直接跳出比赛页面并保存样例,比如in1.txtans3.txt

而没有开始的话,比如 Codeforces Round (Div. 2) and Divide by Zero 2022 这场比赛,我现在输入 cf race 1731 就会看见:

Race CONTEST 1731
Countdown:
121:56:41

有时候距离比赛开始时间较长,countdown 会不稳定,最好一段时间手动退出并重新开启。

创建代码模板

假如你在打一场比赛时,想要在 b 题的文件夹下创建一个代码模板,那该怎么做呢?

你只需要通过 powershell 进入当前目录,然后输入 cf gen,这个文件夹下就会出现一个b.cpp了。

测试代码

我写好了代码,但是我不知道是对是错,what should I do?

你只需要输入 cf test 就可以了。

接下来,如果你的代码正确,你会看见

g++ b.cpp -o b.exe -std=c++14
Passed #1 ... 0.000s 2.910MB

提交代码(不可用)

我写好了一道题,如何提交?

你只需要输入 cf submit 就可以了。

接下来你就会看到相关信息。

其它的

cf watch [all] [<specifier>...]
cf open [<specifier>...]
cf stand [<specifier>...]
cf sid [<specifier>...]
cf race [<specifier>...]
cf pull [ac] [<specifier>...]
cf clone [ac] [<handle>]
cf upgrade

这些对于大多数人来说,都不是什么常用的命令,就不一一解释了。

写在最后

我从 2021 年入坑 Codeforces 以来,已经参加了很多场比赛,也发现速度和效率是比赛中很重要的一部分,希望大家看到这篇文章后也可以开始使用 cf tool ,减少 Codeforces 比赛中不必要的麻烦,提高编程效率,早日获得理想的成绩。

posted @ 2023-08-18 21:59  Monomial  阅读(610)  评论(0)    收藏  举报