示例#1
0
        /// <summary>
        /// Handler the declare lines.
        /// </summary>
        /// <param name="declareLines">The declare lines.</param>
        public static void HandlerDeclareLine(List <string> declareLines)
        {
            RomanHandler romanHandler = new RomanHandler();

            foreach (string declareLine in declareLines)
            {
                string[] split = declareLine.Trim().Split(" ");
                if (split != null && split.Length == 3)
                {
                    if (split[1] == KeyWords.IS)
                    {
                        RomanNumberMap.Add(split[0], RomanCommon.RomanObjs.FirstOrDefault(x => x.Symbol == split[2].ToCharArray()[0]));
                    }
                }
                else if (declareLine.Trim().EndsWith(KeyWords.CREDITS) && split != null && split.Length > 5)
                {
                    string romanString = string.Empty;
                    string productName = split[split.Length - 4];
                    for (int i = 0; i < split.Length - 4; i++)
                    {
                        if (RomanNumberMap[split[i]] != null)
                        {
                            romanString += RomanNumberMap[split[i]].Symbol;
                        }
                    }

                    int    totalNum   = romanHandler.CalculateSymbolsValue(romanString);
                    double totalValue = Convert.ToDouble(split[split.Length - 2]);
                    double price      = 0;
                    if (totalValue > 0 && totalValue > 0)
                    {
                        price = totalValue / totalNum;
                    }
                    Product product = new Product {
                        ProductName = productName, ProductPrice = price
                    };
                    ProductMap.Add(productName, product);
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            string        inputDataFilePath  = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "InputData.txt");
            List <string> needAnswerLines    = new List <string>();
            List <string> canNotHandlerLines = new List <string>();
            List <string> declareLines       = new List <string>();

            using (StreamReader streamReader = new StreamReader(inputDataFilePath))
            {
                string line;
                while (!string.IsNullOrEmpty((line = streamReader.ReadLine())))
                {
                    if (line.Contains(" ?"))
                    {
                        if (line.Contains(" is "))
                        {
                            needAnswerLines.Add(line);
                        }
                        else
                        {
                            canNotHandlerLines.Add(line);
                        }
                    }
                    else
                    {
                        declareLines.Add(line);
                    }

                    Console.WriteLine(line);
                }
            }

            Console.WriteLine("\r\nPlease wait......\r\n");

            Util.HandlerDeclareLine(declareLines);

            #region Output the need answer lines.
            RomanHandler romanHandler = new RomanHandler();
            foreach (string needAnswerLine in needAnswerLines)
            {
                ArrayList result = Util.HandlerAnswerLine(needAnswerLine);
                if (result.Count == 1)
                {
                    Console.WriteLine(string.Format("{0} is {1}", Util.SubStringMainWord(needAnswerLine), romanHandler.CalculateSymbolsValue(result[0].ToString())));
                }
                else if (result.Count == 2)
                {
                    Product product = Util.ProductMap[result[1].ToString()];

                    int            productCount  = romanHandler.CalculateSymbolsValue(result[0].ToString());
                    ProductHandler productHandle = new ProductHandler();
                    Console.WriteLine(string.Format("{0} is {1} Credits", Util.SubStringMainWord(needAnswerLine), productHandle.CountProductValue(product, productCount)));
                }
            }
            #endregion

            #region Output the can not handler lines.
            foreach (string canNotHandlerLine in canNotHandlerLines)
            {
                Console.WriteLine("I have no idea what you are talking about");
            }
            #endregion

            Console.ReadKey();
        }