// Arup Guha
// 10/2/2026
// Solution to COP 3503 Exam 1 Question 1

import java.util.*;

public class e1q1 {

	public static void main(String[] args) {
	
		// A simple test...
		String[] tmp = {"dave","jack","amy","carol","bob","amy","amy","jack","jackie","dave"};
		ArrayList<String> names = new ArrayList<String>();
		for (String x: tmp) names.add(x);
		HashMap<String,Integer> mine = makeMap(names);
		for (String name: mine.keySet())
			System.out.println(name+" "+mine.get(name));
	}

	// Returns a map mapping each unique string in list to the number of times it occurred in list.
	// In addition, the map works by mapping each name in alpha order so the first name alphabetically
	// is mapped to 0, the next to 1, and so forth.
	public static HashMap<String,Integer> makeMap(ArrayList<String> list) {
		
		// First store the names in a treeset.
		TreeSet<String> ts = new TreeSet<String>();
		for (String s: list) ts.add(s);
		
		// Store the final data here.
		HashMap<String,Integer> res = new HashMap<String,Integer>();
		
		// Pull out the items, one by one mapping in numerical order.
		int idx = 0;
		while (ts.size() > 0) 
			res.put(ts.pollFirst(), idx++);
		
		// Return it.
		return res;
	}
}