
// BigHouses.java
// Main file

import java.io.*;
import java.util.*;

// The format of input files should be:
// NAME
// ADDRESS
// NAME
// ADDRESS
// ...


class BigHouses {

	// The only methods of BufferedReader you need are
	// readLine(), and close()
	// To read a file more than once, just call this method again.
	static BufferedReader openInputFile (String filename) throws IOException {
		FileInputStream fis = new FileInputStream (filename);
        InputStreamReader isr = new InputStreamReader (fis);
        return new BufferedReader (isr);
	}

	// The only methods of PrintWriter you need are
	// println(String s) and close().  The only PrintWriter you need is
	// created for you in main.
	static PrintWriter openOutputFile (String filename) throws IOException{
		return new PrintWriter(new FileWriter(filename));
	}

	static void printBigHousesOnePass(String fname, int m, 
										PrintWriter outfile) throws IOException{
		BufferedReader bf = openInputFile(fname);
		String name, addr;
		Hashtable address = new Hashtable();
		Vector NameList;
		
		while ((name = bf.readLine()) != null)
		{
			addr = bf.readLine();
			NameList = (Vector)address.get(addr);
			if(NameList == null)
			{
				NameList = new Vector();
				NameList.addElement(name);
				address.put(addr, NameList);
			}
			else NameList.addElement(name);
			
		}
		bf.close();

		
		//fill me in
	}

	static void printIntersection(String fname1, String fname2, 
								  PrintWriter outfile) throws IOException {
		// fill me in
	}

	public static void main (String [] args) throws IOException {
		String fname1 = "cornell.txt";
		String fname2 = "ithaca.txt";
		int numBiggest = 25; // be sure to test with different values
		PrintWriter output = openOutputFile("hw3answers.txt");

		long start, end;

		output.println("******* Begin Approach A ********");
		System.gc();
		start = System.currentTimeMillis();
		printBigHousesOnePass(fname1, numBiggest, output);
		end = System.currentTimeMillis();
		output.println("******** Approach A: " + (end - start) + " milliseconds"
			           + "*********");

		output.println("******* Intersection ************");
		printIntersection(fname1, fname2, output);
		
		output.close();
	}
}