public HashMap QHashMapMake(List <string> l1) { char[] splitter = { '\n', '\r', ',' }; List <string> list1 = new List <string>(); List <string> list2 = new List <string>(); for (int i = 0; i < l1.Count; i++) { string[] temp = l1[i].Split(splitter); string holding = ""; for (int j = 0; j < temp.Length; j++) { if (j == 0) { list1.Add(temp[j]); } else { holding += (temp[j] + " "); } } list2.Add(holding); } var a1 = list1.ToArray(); var a2 = list2.ToArray(); HashMap hashmap = new HashMap(); for (int i = 0; i < a1.Length; i++) { hashmap.QuadraticProbe(long.Parse(a1[i]), a2[i]); } l1.Clear(); return(hashmap); }
static void Main(string[] args) { HashMap <int, string> myHashMap = new HashMap <int, string>(); Console.ReadKey(); }
public ZipCodes(string pathToCsv) { _pathToCsv = pathToCsv; _table = new HashMap <int, Zip>(); }
static void Main(string[] args) { String[] lines = File.ReadAllLines(@"C:\Users\Matt\Documents\School\Term 5\Programming 4\Assignments\Assignment 4\ItemData.txt"); HashMap <StringKey, Item> hashMap = new HashMap <StringKey, Item>(5); // Load lines from Item data into hash mao foreach (string line in lines) { string[] lineSplit = line.Split(','); StringKey key = new StringKey(lineSplit[0].Trim()); Item value = new Item(lineSplit[0].Trim(), int.Parse(lineSplit[1].Trim()), double.Parse(lineSplit[2].Trim())); hashMap.Put(key, value); } // Remove items that have 0 gold pieces foreach (StringKey key in hashMap.Keys()) { Item item = hashMap.Get(key); if (item != null && item.GetGoldPieces() == 0) { hashMap.Remove(key); } } String[] loot = File.ReadAllLines(@"C:\Users\Matt\Documents\School\Term 5\Programming 4\Assignments\Assignment 4\adventureLoot.txt"); List <Item> items = new List <Item>(); double weight = 0; // Iterate through each list item and perform different actions for (int i = 0; i < loot.Length; i++) { bool found = false; bool capacity = false; foreach (StringKey key in hashMap.Keys()) { // Determine if the loot items exists in the hash map if (loot[i].Equals(key.ToString())) { found = true; Item foundItem = hashMap.Get(key); // Determine if it is possible to add the item to your backpack otherwise print out that you're unable to and raise the capacity flag if ((weight + foundItem.GetWeight()) <= 75) { Console.WriteLine("You have picked up a " + loot[i] + "!"); items.Add(foundItem); weight += foundItem.GetWeight(); } else { Console.WriteLine("You cannot pick up the " + loot[i] + ", you are already carrying " + weight + "KG and it weights " + foundItem.GetWeight() + "KG."); capacity = true; } } } // If item wasn't found in the hash map print out that it wasn't found if (!found) { Console.WriteLine("You find an unknown item that is not in your loot table, you leave it alone. " + loot[i]); } if (capacity) { int total = 0; Console.WriteLine("You must sell the following items:"); // Iterate through items list, calculate and duplicate items and print out contents foreach (Item item in items.ToList()) { int itemQuantity = items.Where(x => x.GetName() == item.GetName()).Count(); if (itemQuantity > 0) { Console.WriteLine(string.Format("{0} - Quantity: {1} - Subtotal: {2}GP", item.ToString(), itemQuantity, item.GetGoldPieces() * itemQuantity)); total += (item.GetGoldPieces() * itemQuantity); } items.RemoveAll(x => x.GetName().Equals(item.GetName())); } Console.WriteLine("Total value of sold items: " + total + "GP"); items = new List <Item>(); } } Console.ReadKey(); }