Creating a custom compare script for DOMjudge involves creating a script that compares the output of the submitted solution to the expected output of the problem. This is usually done in cases where the standard comparison (line by line, ignoring leading/trailing white space) is not sufficient, for example, when comparing floating point numbers.
Here's a simple example of how you can create a custom compare script:
- First, you will need to create a new file for your script. This file can be created in any language that is supported by your DOMjudge installation. For this example, we'll use Python and name the file
compare.py.
#!/usr/bin/env python3
import sys
def main():
# The judge's answer is passed as the first command line argument
judge_answer_path = sys.argv[1]
# The contestant's answer is passed as the second command line argument
contestant_answer_path = sys.argv[2]
with open(judge_answer_path, 'r') as judge_file, open(contestant_answer_path, 'r') as contestant_file:
judge_answer = judge_file.read().strip()
contestant_answer = contestant_file.read().strip()
# Here you can implement your custom comparison logic.
# If the answers match, the script should exit with a status of 0. Otherwise, it should exit with a non-zero status.
if judge_answer == contestant_answer:
sys.exit(0)
else:
sys.exit(1)
if __name__ == "__main__":
main()
- Now, you need to make your script executable. This can be done with the following command:
chmod +x compare.py
- Finally, you need to tell DOMjudge to use your custom compare script for a problem. This can be done by setting the 'compare script' option for the problem to the path of your script. This can be done in the web interface when editing the problem.
Remember, the compare script should return exit code 0 if the output is correct, and non-zero if it is not. The script receives two arguments: the first is a filename with the expected output, and the second is a filename with the program output.
This is a basic example and might not cover all edge cases, so be prepared to modify it as per your needs.