Advertisement
Razhagal

Count of Names

Mar 31st, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class CountOfNames
  8. {
  9.     static void Main()
  10.     {
  11.         //Same as last task, just change the list to <string>
  12.         string namesString = Console.ReadLine();
  13.         string[] allNames = namesString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  14.  
  15.         List<string> letters = allNames.ToList<string>();
  16.  
  17.         letters.Sort();
  18.  
  19.         int counter = 1;
  20.         for (int i = 1; i < letters.Count; i++)
  21.         {
  22.             if (letters[i] == letters[i - 1])
  23.             {
  24.                 counter++;
  25.             }
  26.             else
  27.             {
  28.                 Console.WriteLine("{0} --> {1}", letters[i - 1], counter);
  29.                 counter = 1;
  30.             }
  31.  
  32.             if (i == letters.Count - 1)
  33.             {
  34.                 Console.WriteLine("{0} --> {1}", letters[i], counter);
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement