Skip to content

Instantly share code, notes, and snippets.

@otaruMendez
Last active February 23, 2019 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otaruMendez/a23438fafa4fd56460597e5461097bb7 to your computer and use it in GitHub Desktop.
Save otaruMendez/a23438fafa4fd56460597e5461097bb7 to your computer and use it in GitHub Desktop.
Parsing the Input in the Simulator Class (HashCode Practice Pizza Question)
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]);
pizza.cols = Integer.parseInt(firstLine[1]);
pizza.rowLength = Integer.toString(pizza.rows).length();
pizza.colLength = Integer.toString(pizza.cols).length();
pizza.minIngredientEachPerSlice = Integer.parseInt(firstLine[2]);
pizza.maxCellsPerSlice = Integer.parseInt(firstLine[3]);
pizza.cells = new HashMap<>();
for (int i = 0; i < pizza.rows; i++) {
String l = bufferedReader.readLine();
char[] arr = l.toCharArray();
for (int j = 0; j < pizza.cols; j++) {
String cellHashKey = pizza.getCellHashKey(i, j);
Cell cell = new Cell();
cell.x = i;
cell.y = j;
cell.ingredient = arr[j];
pizza.cells.put(cellHashKey, cell);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment