Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Simple Linux Setup for Testing Solutions to Interactive Problems

Правка en4, от one_autum_leaf, 2023-07-08 21:53:03

Interactive problems are where the input given to your programs changes based on the programs response. This means that in most common competitve programming setups, the only option left is to manually interact with your solution program to check if it's correct.

However in most cases the checker programs(programs which check your solution's correctness) are easy to write. The only difficulty is in getting the checker program to interact with you solution program.

There are already solutions to this, the one over here uses croupier(a python program) to make the two interact.

However, if you have access to a linux terminal you can actually solve this problem way more easily. The following is a bash script that takes as input the names of executable files of you solution program and checker program.

sol=$1
checker=$2

mkfifo pipe_in pipe_out

./$sol < pipe_in 2> error.log  | tee pipe_out &
./$checker < pipe_out | tee pipe_in 

echo "------------------- Error ------------------"
cat error.log
rm error.log
rm pipe_in
rm pipe_out

Save this by the name (say) run_checker.sh. Then run the following commands.

g++ -o E E.cpp
g++ -o E_checker E_checker.cpp
chmod +x run_checker.sh
./run_checker.sh E E_checker

Here E.cpp contains your solution program and E_checker.cpp contains your checker program.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en9 Английский one_autum_leaf 2023-07-08 22:09:17 5 Tiny change: 'erminal:\nThe Linu' -> 'erminal:\n==================\nThe Linu'
en8 Английский one_autum_leaf 2023-07-08 22:07:51 0 (published)
en7 Английский one_autum_leaf 2023-07-08 22:06:16 47 Tiny change: 'ows : \n\n\n\n\n\n' -> 'ows : \n\n![ ](https://i.imgur.com/iIYkaMB.png)'
en6 Английский one_autum_leaf 2023-07-08 22:03:36 341 Tiny change: 'rograms.\n`g++ -o E E.cpp`\n`g++ -o ' -> 'rograms.\n\n`g++ -o E E.cpp`\n\n`g++ -o '
en5 Английский one_autum_leaf 2023-07-08 21:59:32 969 Tiny change: 'hecker.sh E E_checker' -> 'hecker.sh E E_checker'
en4 Английский one_autum_leaf 2023-07-08 21:53:03 233 Tiny change: 'heck your program's correct' -> 'heck your solution's correct'
en3 Английский one_autum_leaf 2023-07-08 21:48:50 461
en2 Английский one_autum_leaf 2023-07-08 21:43:46 23
en1 Английский one_autum_leaf 2023-07-08 21:43:13 793 Initial revision (saved to drafts)