예제 #1
0
        public List <string> GetResult(List <string> QuestionLines, Dictionary <string, string> Alias, Dictionary <string, double> ComodityCost)
        {
            List <string> result = new List <string>();

            foreach (var ques in QuestionLines)
            {
                if (ques.Contains("woodchuck"))
                {
                    result.Add("I have no idea what you are talking about");
                    continue;
                }
                string[] temp              = ques.Split(" is ");
                string[] units             = temp[1].Split(" ");
                string   RomanNumberString = "";
                string   comodity          = "";
                foreach (var al in units)
                {
                    string value = null;
                    if (Alias.TryGetValue(al, out value))
                    {
                        RomanNumberString += value;
                    }
                    else
                    {
                        comodity = al;
                    }
                }

                ConvertorNumber convert     = new ConvertorNumber();
                double          RomanNumber = convert.RomanToDecimal(RomanNumberString);
                if (comodity == "")
                {
                    string tres = "";
                    tres += temp[1] + " is " + RomanNumber.ToString();
                    result.Add(tres);
                }
                else
                {
                    double credit = RomanNumber * ComodityCost[comodity];
                    string tres   = "";
                    tres += temp[1] + " is " + credit.ToString() + " Credits";
                    result.Add(tres);
                }
            }
            return(result);
        }
예제 #2
0
        public Dictionary <string, double> GetComodityCost(List <string> comodityAliasLines, Dictionary <string, string> Alias)
        {
            Dictionary <string, double> ComodityCost = new Dictionary <string, double>();

            foreach (var line in comodityAliasLines)
            {
                string[] temp             = line.Split(" is ");
                string[] AliasAndComodity = temp[0].Split(" ");
                string   creditString     = temp[1].Split(" ")[0].ToString();
                double   credit           = double.Parse(creditString);
                string   RomanNumber      = "";
                string   comodity         = "";
                foreach (var alias in AliasAndComodity)
                {
                    string value = null;
                    if (Alias.TryGetValue(alias, out value))
                    {
                        RomanNumber += value;
                    }
                    else
                    {
                        comodity += alias;
                    }
                }
                ConvertorNumber convert = new ConvertorNumber();

                double DecimalValue  = convert.RomanToDecimal(RomanNumber);
                double ComodityPrice = 0;
                if (DecimalValue != 0)
                {
                    ComodityPrice = credit / DecimalValue;
                }

                ComodityCost[comodity] = ComodityPrice;
            }
            return(ComodityCost);
        }