Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                SortManager sortManager = new SortManager();

                var sortedNumbers = sortManager.Sort("inputNumbers.csv");

                Console.WriteLine("Sorted Numbers are ......");
                foreach (var number in sortedNumbers)
                {
                    Console.WriteLine(number);
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured,Failed to sort numbers");
                Console.WriteLine(e);
            }
        }
        public IList <string> Convert(List <int> numbers)
        {
            //sorting the number list
            SortManager _sortManager = new SortManager();

            numbers = _sortManager.InnerSort(numbers);

            var words = new List <string>();

            foreach (var number in numbers)
            {
                string word;
                int    remainder;
                if (number / 100 != 0)
                {
                    if (_wordsOneToNineteen.TryGetValue(number / 100, out word))
                    {
                        remainder = number % 100;
                        word      = word + " Hundred";
                        string word2;
                        if (remainder != 0)
                        {
                            if (_wordsOneToNineteen.TryGetValue(remainder, out word2))
                            {
                                word = word + " and " + word2;
                            }
                            else if (_wordsMultiplesOfTenFromTwentyToHundred.TryGetValue(remainder / 10, out word2))
                            {
                                string word3;
                                word      = word + " and " + word2;
                                remainder = remainder % 10;
                                if (remainder != 0)
                                {
                                    if (_wordsOneToNineteen.TryGetValue(remainder, out word3))
                                    {
                                        word = word + " " + word3;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    remainder = number % 100;
                    if (_wordsOneToNineteen.TryGetValue(remainder, out word))
                    {
                    }
                    else if (_wordsMultiplesOfTenFromTwentyToHundred.TryGetValue(remainder / 10, out word))
                    {
                        remainder = remainder % 10;
                        string word2;
                        if (_wordsOneToNineteen.TryGetValue(remainder, out word2))
                        {
                            word = word + " " + word2;
                        }
                    }
                    else
                    {
                        word = "Zero";
                    }
                }
                words.Add(word);
            }
            return(words);
        }