private List <MultplePrimKey> ParseQuestion(string question) { List <MultplePrimKey> list = new List <MultplePrimKey>(); string[] tempArray = question.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (tempArray.Length == 0) { return(list); } string lastStr = tempArray[tempArray.Length - 1].Trim(new char[] { '.' }); string[] stops = lastStr.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); if (stops.Length < 2) { return(list); } for (int i = 0; i < stops.Length - 1; i++) { MultplePrimKey key = new MultplePrimKey() { Key1 = stops[i], Key2 = stops[i + 1] }; list.Add(key); } return(list); }
public static IDictionary <MultplePrimKey, int> LoadInputs(string path) { Dictionary <MultplePrimKey, int> roads = new Dictionary <MultplePrimKey, int>(); using (StreamReader sr = new StreamReader(path)) { string line = sr.ReadToEnd(); if (line.Equals(string.Empty)) { return(roads); } else { line = line.Replace("Graph:", ""); string[] paths = line.Split(new char[] { ',', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < paths.Length; i++) { MultplePrimKey key = new MultplePrimKey(); char[] items = paths[i].ToCharArray(); if (items.Length == 3) { key.Key1 = items[0].ToString(); key.Key2 = items[1].ToString(); int value; if (int.TryParse(items[2].ToString(), out value)) { roads.Add(key, value); } else { throw new Exception(ConstStr.BADINPUTGRAPHERROR); } } else { throw new Exception(ConstStr.BADINPUTGRAPHERROR); } } } } return(roads); }