This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void printOutput () { | |
PrintWriter writer = null; | |
try { | |
writer = new PrintWriter(this.fileName + ".out", "UTF-8"); | |
int noOfSlices = pizzaCutter.cutSlices.size(); | |
writer.print(noOfSlices); | |
writer.println(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void simulate() { | |
pizzaCutter = new PizzaCutter(pizza); | |
pizzaCutter.cutPizza(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void parseInput () { | |
int bufferSize = 8 * 1024; | |
BufferedReader bufferedReader = null; | |
try { | |
bufferedReader = new BufferedReader(new FileReader(this.fileName + ".in"), bufferSize); | |
String line = bufferedReader.readLine(); | |
String[] firstLine = line.split(" "); | |
pizza = new Pizza(); | |
pizza.rows = Integer.parseInt(firstLine[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
String[] inputs = {"a_example", "b_small", "c_medium", "d_big"}; | |
for (String in: inputs) { | |
String fileName = "path/to/datasets/" + in; | |
Simulator simulator = new Simulator(fileName); | |
simulator.parseInput(); | |
simulator.simulate(); | |
simulator.printOutput(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Simulator { | |
private String fileName; | |
private Pizza pizza; | |
private PizzaCutter pizzaCutter; | |
public Simulator (String fileName) { | |
this.fileName = fileName; | |
} | |
public void parseInput () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Slice { | |
int startX; | |
int endX; | |
int startY; | |
int endY; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PizzaCutter { | |
Pizza pizza; | |
ArrayList<Slice> cutSlices = new ArrayList<>(); | |
public PizzaCutter (Pizza pizza) { | |
this.pizza = pizza; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pizza { | |
int rows; | |
int cols; | |
int minIngredientEachPerSlice; | |
int maxCellsPerSlice; | |
HashMap<String, Cell> cells; | |
int rowLength; | |
int colLength; | |
public String getCellHashKey (int x, int y) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Cell { | |
int x; | |
int y; | |
char ingredient; | |
boolean cutOut = false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PizzaCutter { | |
Pizza pizza; | |
ArrayList<Slice> cutSlices = new ArrayList<>(); | |
public PizzaCutter (Pizza pizza) { | |
this.pizza = pizza; | |
} | |