コード例 #1
0
        public static void Main()
        {
            string[] words =
                new string[] { "Java", "C#", "JavaScript", "Ajax", "SQL", "PHP", "Ajax", "Java", "PHP", "JavaScript", "SQL", "SQL", "Java", "JavaScript", "JavaScript", "Ajax", "Java" };
            IDictionary <string, int> pairs = new Dictionary <string, int>();

            for (int i = 0; i < words.Length; i++)
            {
                if (pairs.ContainsKey(words[i]))
                {
                    pairs[words[i]]++;
                }
                else
                {
                    pairs.Add(words[i], 1);
                }
            }

            IDictionary <string, int> oddOccour = new Dictionary <string, int>();

            pairs.Where(x => x.Value % 2 == 1).ToList().ForEach(x => oddOccour.Add(x));

            string result = Formater.FormatPairsForTemplate(StringFormatForResult, oddOccour);

            System.Console.WriteLine(result);
        }
コード例 #2
0
        public static void Main()
        {
            IDictionary <string, int> pairs = new Dictionary <string, int>();

            using (StreamReader reader = new StreamReader("..\\..\\words.txt"))
            {
                reader
                .ReadToEnd()
                .Split(new char[] { '?', ' ', '.', '-', ',', '!', '\n', '"', '\'', ';', '\r' }, StringSplitOptions.RemoveEmptyEntries)
                .ToList()
                .ForEach(word =>
                {
                    string lowerWord = word.ToLower();
                    if (pairs.ContainsKey(lowerWord))
                    {
                        pairs[lowerWord]++;
                    }
                    else
                    {
                        pairs.Add(lowerWord, 1);
                    }
                });
            }

            IDictionary <string, int> orderedPairs = new Dictionary <string, int>();

            pairs.OrderBy(x => x.Value).ToList().ForEach(x => orderedPairs.Add(x));

            string result = Formater.FormatPairsForTemplate(StringFormaterResult, orderedPairs);

            Console.WriteLine(result);
        }
コード例 #3
0
        public static void Main()
        {
            double[] arrayOfValues          = new double[] { 0.09444, 3, 4, 4, -2.5, -3.14, 3, 4, 3, -2.5, 3, -3.14, 4, -2.5, 3, 3, 9, 3, -2.5, 3, 9, 9, -2.5, 3.123, 3.123, 9, 3, -3.14, 000.09444 };
            IDictionary <double, int> pairs = new Dictionary <double, int>();

            for (int i = 0; i < arrayOfValues.Length; i++)
            {
                if (pairs.ContainsKey(arrayOfValues[i]))
                {
                    pairs[arrayOfValues[i]]++;
                }
                else
                {
                    pairs.Add(arrayOfValues[i], 1);
                }
            }

            string result = Formater.FormatPairsForTemplate(StringFormatForResult, pairs);

            Console.WriteLine(result);
        }