cf tool 使用指南

发布时间 2023-08-18 22:03:48作者: Monomial

本文作者使用 powershell 而非 cmd 。

本文作者使用 powershell 而非 cmd 。

本文作者使用 powershell 而非 cmd 。

下载

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

这不是 xalanq 的原版,原版有 bug。

对于 Windows 系统,请下载cf.exe

配置

开始

首先,将cf.exe放入一个加入系统 Path 的路径。

登录用户

Windows + R键打开 cmd,然后键入以下内容

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 hanyuchen2020~

(当然这不是我的号,但还是要膜拜hyc)

配置代码模板

再次键入

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"):

这一段又臭又长的东西,我们只需要键入 50(对于C++14)。

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

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

创建代码模板

假如你在打Codeforces Round #840 (Div. 2) and Enigma 2022 - Cybros LNMIIT这场比赛时,想要在 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就可以了。

接下来你就会看到:

Submit CONTEST 1721, problem c
Current user: shuger
Submitted
     #: 186353883
  when: 2022-12-22 20:53
  prob: C - Min-Max Array Transformation
  lang: GNU C++14
status: Accepted
  time: 374 ms
memory: 3.03 MB

这个实在不好改,就用自己的

其它的

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 以来,已经参加了很多场比赛,目前 rating 已经超过了 1600,希望大家看到这篇文章后也可以开始使用 cf tool ,减少 Codeforces 比赛中不必要的麻烦,提高编程效率,早日获得理想的成绩。