// Arup Guha
// 8/25/2026
// Code illustrating use of built in data structures in Java.

import java.util.*;

class BuiltInDS {
    public static void main(String[] args) {

        // Test array list.
        ArrayList<Integer> myList = new ArrayList<Integer>();
        myList.add(8);
        myList.add(3);
		
		// How to get size.
        System.out.println(myList.size());
		
		// Iterator loop to print items.
        for (Integer x: myList)
            System.out.println(x);
			
		// Index loop to do the same.
        for (int i=0; i<myList.size(); i++)
            System.out.println(myList.get(i));
            
		// Fun test for a set...
        Random r = new Random();
        HashSet<Integer> mine = new HashSet<Integer>();
        
		// How many times do we have to generate a random integer from 0 to 99 until
		// we generate each unique integer at least once?
		int cnt = 0;
        while (mine.size() < 100) {
            int x = r.nextInt(100);
            mine.add(x);
            cnt++;
        }

		// Ta da!
        System.out.println("need to buy "+cnt+" cards.");
        
		// Maps allow us to store associated information with each object (key)
		// stored in the map.
		
		// Here we give each unique string an integer code, starting at 0.
        HashMap<String,Integer> map = new HashMap<String,Integer>();
        Scanner stdin = new Scanner(System.in);
		
		// Storing both the code and # of unique items assiged.
        int id = 0;
		
		// Reads in 10 names.
        for (int i=0; i<10; i++) {
            String name = stdin.next();

			// Only add a new entry if the key is new.
            if (!map.containsKey(name))
			
				// The post increment works nicely here.
                map.put(name,id++);
        }

		// One way to loop through each key in a map.
        for (String name: map.keySet()) {
            System.out.println(name+": "+map.get(name));
        }
    }
}
