Example #1
0
        public static void GetMetalCredits(string metalString)
        {
            string[] metalStmt = metalString.Split(new string[] { " is " }, StringSplitOptions.None);

            string[] unitsMetalStr = metalStmt.FirstOrDefault().Split(' ');

            int totalMetalValue = Convert.ToInt32(metalStmt.LastOrDefault().Split(' ')[0]);

            string romanNumeral = "";
            string metalName    = "";

            for (int i = 0; i < unitsMetalStr.Length; i++)
            {
                if (UnitCredits.Keys.Contains(unitsMetalStr[i]))
                {
                    romanNumeral = romanNumeral + UnitCredits[unitsMetalStr[i]];
                }
                else
                {
                    metalName = unitsMetalStr[i];
                }
            }

            int base10Number = RomanNumeralConvention.ConvertRomanNumeralToBase10(romanNumeral);

            float metalCredit = (float)totalMetalValue / base10Number;

            if (!MetalCredits.Keys.Contains(metalName))
            {
                MetalCredits.Add(metalName, metalCredit);
            }
        }
        static void GenerateAnswer()
        {
            for (int i = 0; i < _questionsStr.Count; i++)
            {
                string ques = _questionsStr[i].Trim();
                if (string.IsNullOrEmpty(ques))
                {
                    continue;
                }
                string[] questionArr = ques.Split(new string[] { " is " }, StringSplitOptions.None);

                if (questionArr.Count() < 2 || !(questionArr[0].Split(' ').Any(t => IntergalacticNotation.UnitCredits.Keys.Contains(t.Trim())) ||
                                                 !questionArr[0].Split(' ').Any(t => IntergalacticNotation.MetalCredits.Keys.Contains(t.Trim()))))
                {
                    Console.WriteLine("I have no idea what you are talking about");
                    continue;
                }

                string question = questionArr[1];

                string[] quessplt   = question.Split(' ');
                string   romanNo    = "";
                float    metalValue = 0.0F;
                for (int j = 0; j < quessplt.Length; j++)
                {
                    if (IntergalacticNotation.UnitCredits.Keys.Contains(quessplt[j].Trim()))
                    {
                        romanNo = romanNo + IntergalacticNotation.UnitCredits[quessplt[j].Trim()];
                    }
                    else if (IntergalacticNotation.MetalCredits.Keys.Contains(quessplt[j].Trim()))
                    {
                        metalValue = IntergalacticNotation.MetalCredits[quessplt[j].Trim()];
                    }
                }

                int base10Number = RomanNumeralConvention.ConvertRomanNumeralToBase10(romanNo);

                float totaMetalCredit = metalValue == 0.0F ? base10Number : metalValue * base10Number;


                Console.WriteLine($"{question} is {totaMetalCredit}");
            }
        }