How to prepare test case for USACO problems

How to prepare test case for USACO problems

by Sharad Goyal -
Number of replies: 3

I am trying to setup USACO problems in my Moodle Open source code runner. I do not know how to specify the file input which is given by one of the students in the solution. 

import java.util.*;
import java.io.*;

public class billboard {

	public static void main(String[] args) throws Exception {

		// Read the grid.
		Scanner stdin = new Scanner(new File("billboard.in"));

		// Mark both seen billboards.
		boolean[][] see = new boolean[2001][2001];
		for (int i=0; i<2; i++) {

			int x1 = stdin.nextInt()+1000;
			int y1 = stdin.nextInt()+1000;
			int x2 = stdin.nextInt()+1000;
			int y2 = stdin.nextInt()+1000;

			for (int x=x1; x<x2; x++)
				for (int y=y1; y<y2; y++)
					see[x][y] = true;
		}

		// Mark squares that can't be seen.
		int x1 = stdin.nextInt()+1000;
		int y1 = stdin.nextInt()+1000;
		int x2 = stdin.nextInt()+1000;
		int y2 = stdin.nextInt()+1000;
		for (int x=x1; x<x2; x++)
			for (int y=y1; y<y2; y++)
				see[x][y] = false;

		// Count which ones can be seen now.
		int res = 0;
		for (int i=0; i<=2000; i++)
			for (int j=0; j<2000; j++)
				if (see[i][j])
					res++;

		// Ta da!
		PrintWriter out = new PrintWriter(new FileWriter("billboard.out"));
		out.print(res);
		out.close();
		stdin.close();
	}
}

In reply to Sharad Goyal

Re: How to prepare test case for USACO problems

by Richard Lobb -

CodeRunner questions are usually set up with the standard input and expected output for each test case explicitly stated in the list of test cases. The student's answer program should then read from standard input and write to standard output. Many (most?) major programming contests - e.g. ICPC - operate with standard input/output rather than named file(s).

It is possible to write a CodeRunner question type that takes the test case data from a set of support files (or a single zip file) but that requires advanced CodeRunner development skills and it sounds like you're a relative newcomer? I'd recommend you start with the much simpler approach of copying the data for each test into a test case in the question authoring form.

In reply to Richard Lobb

Re: How to prepare test case for USACO problems

by Sharad Goyal -

Thank you. I am able to set up the first USACO problem and test it successfully. Can I export the template and modify and import it further?

Is there any UNIX XML template location where I can download the problems?

In reply to Sharad Goyal

Re: How to prepare test case for USACO problems

by Richard Lobb -

If you have a template that you wish to re-use, you should save your question as a new question type. See the documentation.

I don't know of any public repo of USACO problems.