CodeJam Saving The Universe
<p>I recently discovered Google CodeJam and have been going through some of the older problems.  This relatively easy problem has been giving me some trouble (<a href="http://code.google.com/codejam/contest/32013/dashboard#s=p0&amp;a=0" rel="nofollow">http://code.google.com/codejam/contest/32013/dashboard#s=p0&amp;a=0</a>).</p>

<p>Im not sure what I am doing wrong and could really use some help.</p>

<p>Here is my code.</p>

<pre><code>import java.util.*;
import java.io.*;

public class SavingTheUniverse {

public static void main(String args[]) {
    Scanner scan = null;
    PrintWriter out = null;

    try {
        scan = new Scanner(new File("A-small-practice.in"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    try {
        out = new PrintWriter(new FileWriter("output.txt"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    int cases = scan.nextInt();
    int size;
    int queries;
    int switches = 0;
    int y = 1;
    Set&lt;String&gt; set = new HashSet&lt;String&gt;();

    while (scan.hasNext()) {
        size = scan.nextInt();
        scan.nextLine();
        for (int i = 0; i &lt; size; i++) {
            scan.nextLine();
        }
        queries = scan.nextInt();
        scan.nextLine();

        for (int j = 0; j &lt; queries; j++) {
            set.add(scan.nextLine());
            if (set.size() == size) {
                switches++;
                set.clear();
            }
        }

        out.print("Case #" + y + ": " + switches);
        switches = 0;
        set.clear();
        y++;
    }

    out.close();
    scan.close();

}
</code></pre>

<p>}</p>

<p>Here is the output I am getting from this.</p>

<pre><code>Case #1: 0
Case #2: 0
Case #3: 1
Case #4: 1
Case #5: 3
Case #6: 3
Case #7: 50
Case #8: 32
Case #9: 6
Case #10: 3
Case #11: 0
Case #12: 1
Case #13: 4
Case #14: 2
Case #15: 0
Case #16: 1
Case #17: 2
Case #18: 3
Case #19: 1
Case #20: 1
</code></pre>
