import java.io.*;
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.regex.Pattern;

public class jpn_lending
{
    // Name of two files to compare
    final static String file1 = "input.txt";  // japanese library holding info.
    
    final static String[] compare_files = {"book_lib.txt", "ser_lib.txt"};
    final static String[] compare_headers = {"\n***************Book Lending Libraries*************\r\n",
					     "\n**********Article Delivery Libraries********\r\n"};

    // Name of file to write output to
    final static String outfile = "input_output.txt";

    public static void main(String args[])
    {
	/* Store all University names into hashtable */
	ArrayList<Hashtable<String, String>> hash = new ArrayList<Hashtable<String, String>>();
	hash.add(new Hashtable<String, String>());
	hash.add(new Hashtable<String, String>());

	try{
    	    for(int a = 0; a < compare_files.length; a++)
		{
		    FileInputStream fin = new FileInputStream(compare_files[a]);
		    BufferedReader input = new BufferedReader(new InputStreamReader(fin));
		
		    String line;
		    while((line = input.readLine()) != null)
			{
			    if(line.trim().length() < 1)
				continue;
			    else{
				String key = line.trim();
				hash.get(a).put(key, ":-)");
			    }
			}
		}
	}
	catch(Exception e){
	    e.printStackTrace();
	}

	try{
	    BufferedWriter out = new BufferedWriter(new FileWriter(outfile));

 	    for(int a =0; a < 2; a++)
		{
		    FileInputStream fin = new FileInputStream(file1);
		    BufferedReader input = new BufferedReader(new InputStreamReader(fin));
	    
		    out.write("\n******************************************************\r\n");
		    out.write(compare_headers[a]);
		    out.write("\n******************************************************\r\n");

		    String line;
		    String tline;
		    while((line = input.readLine()) != null)
			{		    
			    String uni = line.trim();
			    if(uni.length() < 0)
				continue;
			    else if(hash.get(a).containsKey(uni) &&(tline = input.readLine()) != null)
				{
				    out.write(line + "\r\n");
				    out.write(tline + "\r\n\n");
				}
			}

		    fin.close();
		}
	    out.close();
	}
	catch(Exception e){
	    e.printStackTrace();
	}


    }
}


