This repository contains an input reader implemented in Java that can read from files or
folders (ie all files inside a folder). The purpose of this project is to take over
tedious input- and output management in coding competitions. This repository can be used
as a template to build your solution on.
This template was created specifically for the CCC.
Made by Philippe Zorman, Lutu
The application provides an interface in Solver.java with two methods, which are both run for
every file in the configured inputPath:
-
solve(): Computes the result of each testcase. A working program should contain the following aspects:- Read lines of an input file with a given Java Scanner (see Documentation)
- Compute result for the input
- Write the result to an output file with a given Java FileWriter
Example:
//Outputs the sum of the space-separated integers public static void solve(Scanner reader, FileWriter writer) throws IOException { int maxRuns = reader.nextInt(); reader.nextLine(); for(int run = 0;run < maxRuns;run++) { //compute sum of each line List<Integer> list = IOUtils.readList(reader, " ", Integer::parseInt); int sum = list.stream().mapToInt(Integer::intValue).sum(); writer.write(sum + "\n"); } }
-
verify(): Is run aftersolve()to verify the solution of your output specific to CCC. For this to work a filevisualizer.htmlhas to be present, which can verify results for given inputs. A working program should contain the following:- Read lines of the input file that are used for one testcase
- Read lines of the output file that are used for one testcase
- Check validity with the given verifier
Example:
//Verifies a testcase with one input line and one output line public static void verify(Scanner input, Scanner output, SolutionVerifier verifier) throws IOException { int maxRuns = input.nextInt(); input.nextLine(); for(int run = 0;run < maxRuns;run++) { String inputLine = input.nextLine(); String outputLine = output.nextLine(); verifier.checkValidity(run, inputLine, outputLine); } }
The application can be configured by changing the resources/config.xml file accordingly.
For configuration details, look inside the file.
Prerequisites
Run with IntelliJ (Recommended)
This project is optimized for IntelliJ IDEA.
- Open the project in IntelliJ.
- Navigate to
src/main/java/solver/Solver.java. - Click the green Run arrow (▶) next to the
mainmethod.
Run with Maven (CLI)
Alternatively, you can run the solution directly from your terminal:
mvn clean compile exec:java -Dexec.mainClass="solver.Solver"