Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program that reads a list of letters and prints for each letter how many times it appears in the list. The letters should be listed in alphabetical order.
- namespace _11.CountOfLetters
- {
- using System;
- public class CountOfLetters
- {
- public static void Main(string[] args)
- {
- checked
- {
- Console.WriteLine("Enter your List of letters on single line, separated by a space!");
- string inputLine = Console.ReadLine();
- char[] separators = new char[] { ' ', ',', ';' };
- string[] letters = inputLine.Split(separators, StringSplitOptions.RemoveEmptyEntries);
- if (letters.Length > 0)
- {
- Array.Sort(letters);
- int countLetterAppears = 1;
- for (int i = 1; i < letters.Length; i++)
- {
- if (letters[i] == letters[i - 1])
- {
- countLetterAppears++;
- }
- else
- {
- Console.WriteLine("{0} -> {1}", letters[i - 1], countLetterAppears);
- countLetterAppears = 1;
- }
- }
- Console.WriteLine("{0} -> {1}", letters[letters.Length - 1], countLetterAppears);
- }
- else
- {
- Console.WriteLine("Error! - Empty List!!!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement