Download All Files (as .zip)

I was actually at this regional competition and this file is the raw code that I used to be marked. I've fixed up this code with comments and made it more of a perfect solution over here.

Play the "MOE Millions" scratch and win card and you could win up to $1 000 000! Or you could win less than that! Or you might win nothing at all. There are 10 possible prizes: $1, $2, $5, $10, $50, $100, $1000, $10 000, $500 000 and $1 000 000.

$10 | $100 | |

$10 | $1 | $50 |

$50 | $1000 | $1 |

To play, scratch off the squares on a 3x3 grid one at a time. If you find 3 matching prize amounts under the scratchy stuff, you win that amount. It's that simple! Each card will contain a maximum of one set of 3 matching symbols. Employees of the Ministry of Education and their families are not eligible for any prizes.

OK, you've got your card, and you've scratched off 8 of the squares as shown on the right. What fabulous prizes could you win when you scratch off that final square?

DATA11.txt (DATA12.txt for the second try) will contain 10 test cases. Each test case will consist of nine lines representing the nine squares on the card. The first line is for the top left box, the second is for the top middle box, then top right, then middle row left, and so on down to the bottom right corner. If a box has been scratched, the line for that box will contain the prize amount that is revealed. If not, the line will contain a question mark. The cards could be in any state of play, ranging from just starting out (no boxes scratched yet) to completely finished (all boxes scratched).

Your job is to output a list of all prizes the cardholder can or will win in order from lowest to highest, separated by spaces. Each card in the input should be represented by a single line in your output. If no prize is possible, output the exact string "No Prizes Possible".

Note that the sample input below only contains one test case, but the real data files will contain 10 test cases, one after another, with no blank lines between. Your output should therefore consist of 10 lines.

$10 $100 ? $10 $1 $50 $50 $1000 $1Sample Input

$1 $10 $50Sample Output

import java.util.*; import java.io.*; public class Problem_1 { public static void main(String[] args) { try { //System.out.println("Stated"); Scanner file = new Scanner(new File("C:\\Users\\Tony\\Desktop\\DATA11.txt")); while(file.hasNextLine()) { ArrayList<String> list = new ArrayList<String>(); for (int l = 0; l < 9; l++) { list.add(file.nextLine()); } String[][] array = new String[3][3]; array[0][0] = list.get(0); array[0][1] = list.get(1); array[0][2] = list.get(2); array[1][0] = list.get(3); array[1][1] = list.get(4); array[1][2] = list.get(5); array[2][0] = list.get(6); array[2][1] = list.get(7); array[2][2] = list.get(8); int blanks = 0, one=0, two=0, five=0, ten=0, fifty=0, hundred=0, thousand=0, tenThou=0, fiveHunThou=0, million=0; boolean nonePossible = false; for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) { if (array[r][c].equals("$1")) one++; if (array[r][c].equals("$2")) two++; if (array[r][c].equals("$5")) five++; if (array[r][c].equals("$10")) ten++; if (array[r][c].equals("$50")) fifty++; if (array[r][c].equals("$100")) hundred++; if (array[r][c].equals("$1000")) thousand++; if (array[r][c].equals("$10000")) tenThou++; if (array[r][c].equals("$500000")) fiveHunThou++; if (array[r][c].equals("$1000000")) million++; if (array[r][c].equals("?")) blanks++; } } if (one > 2 || two > 2 || five > 2 || ten > 2 || fifty > 2 || hundred > 2 || thousand > 2 || tenThou > 2 || fiveHunThou > 2 || million > 2) { if (one > 2) System.out.println("$1"); if (two > 2) System.out.println("$2"); if (five > 2) System.out.println("$5"); if (ten > 2) System.out.println("$10"); if (fifty > 2) System.out.println("$50"); if (hundred > 2) System.out.println("$100"); if (thousand > 2) System.out.println("$1000"); if (tenThou > 2) System.out.println("$10000"); if (fiveHunThou > 2) System.out.println("$500000"); if (million > 2) System.out.println("$1000000"); } else { if (blanks > 2) System.out.print("$1 $2 $5 $10 $50 $100 $1000 $10000 $500000 $1000000"); else if (blanks == 2) { if (one > 0) System.out.print("$1 "); if (two > 0) System.out.print("$2 "); if (five > 0) System.out.print("$5 "); if (ten > 0) System.out.print("$10 "); if (fifty > 0) System.out.print("$50 "); if (hundred > 0) System.out.print("$100 "); if (thousand > 0) System.out.print("$1000 "); if (tenThou > 0) System.out.print("$10000 "); if (fiveHunThou > 0) System.out.print("$500000 "); if (million > 0) System.out.print("$1000000 "); if ((one + two + five + ten + fifty + hundred + thousand + tenThou + fiveHunThou + million) == 0) { nonePossible = true; } } else if (blanks == 1) { if (one > 1) System.out.print("$1 "); if (two > 1) System.out.print("$2 "); if (five > 1) System.out.print("$5 "); if (ten > 1) System.out.print("$10 "); if (fifty > 1) System.out.print("$50 "); if (hundred > 1) System.out.print("$100 "); if (thousand > 1) System.out.print("$1000 "); if (tenThou > 1) System.out.print("$10000 "); if (fiveHunThou > 1) System.out.print("$500000 "); if (million > 1) System.out.print("$1000000 "); if (one < 2 && two < 2 && five < 2 && ten < 2 && fifty < 2 && hundred < 2 && thousand < 2 && tenThou < 2 && fiveHunThou < 2 && million < 2) { nonePossible = true; } } else if (blanks == 0) { if (one > 2) System.out.print("$1 "); if (two > 2) System.out.print("$2 "); if (five > 2) System.out.print("$5 "); if (ten > 2) System.out.print("$10 "); if (fifty > 2) System.out.print("$50 "); if (hundred > 2) System.out.print("$100 "); if (thousand > 2) System.out.print("$1000 "); if (tenThou > 2) System.out.print("$10000 "); if (fiveHunThou > 2) System.out.print("$500000 "); if (million > 2) System.out.print("$1000000 "); if (one < 3 && two < 3 && five < 3 && ten < 3 && fifty < 3 && hundred < 3 && thousand < 3 && tenThou < 3 && fiveHunThou < 3 && million < 3) { nonePossible = true; } } if (!nonePossible) System.out.println(); else System.out.println("No Prizes Possible"); } } } catch (Exception e) { e.printStackTrace(); } } }

DOWNLOAD as .java
## My test cases (as .txt files):

Using their sample input:

$10 $100 ? $10 $1 $50 $50 $1000 $1

And the output to that is:

$1 $10 $50DOWNLOAD as .txt

And that is exactly the expected output.

Using their first judging test input:

$500000 $100 $1000 $10 $5 $2 $1000000 $1 ? $1000 $500000 $100 $2 $10 ? $100 $5 $10000 $50 $100 $10000 $500000 ? $50 $500000 $1 $100 $100 $50 $50 $500000 $5 $1000000 $50 $1000 ? ? $1000 $5 $5 $1000 $2 $1000 $2 $500000 $50 $2 $500000 ? $5 $10 ? $100 $10000 ? $500000 $1000000 $100 $100 $1000000 $500000 ? $10000 ? ? $10000 $50 $2 $1000000 $1000 ? $100 $500000 $1000000 $10000 $1000 $10 $50 $1 $100 $2 $10 $1 $5 $2 $1 $50 $50 $1 $10000

And the output to that is:

No Prizes Possible $100 $50 $100 $500000 $50 $1000 $2 $5 $10 $50 $100 $10000 $500000 $100 $10000 $500000 $1000000 $1 $2 $5 $10 $50 $100 $1000 $10000 $500000 $1000000 No Prizes Possible $1DOWNLOAD as .txt

And that is exactly the expected output.

Using their second judging test input:

$1000 $10 $5 $1000 $1 $1000000 $1000000 $5 $1000000 ? ? ? ? ? ? ? ? ? $100 $100 $10000 $10000 $5 $100 $5 ? ? ? ? $100 $50 $1000000 $10 $500000 $1 $5 $50 $100 ? $1000000 $1000000 ? $100 $50 $1000 $1000000 $1000000 ? $100 $1000 $10 $500000 $10000 $1000000 $2 $2 $1000000 ? $1000 $5 $50 $5 $500000 $10000 $1000 $5 $1 $10 $1 $100 ? $1000000 $2 $10 $1 ? $1000000 $5 $10000 $50 $500000 $1000 $2 $5 $5 $50 $1000 $50 $10 $2

And the output to that is:

$1000000 $1 $2 $5 $10 $50 $100 $1000 $10000 $500000 $1000000 $100 $1 $5 $10 $50 $100 $500000 $1000000 $50 $100 $1000 $1000000 $1000000 $2 $5 $1 No Prizes Possible No Prizes Possible

And that is exactly the expected output.

DOWNLOAD as .txt
Created: June 26, 2014

Completed in full by: Michael Yaworski