Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that reads some text from the console and counts the occurrences of each character in it. Print the results in alphabetical (lexicographical) order. */
- namespace _06.CountSymbols
- {
- using System;
- using System.Collections.Generic;
- class CountSymbols
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter your text on single line: ");
- string text = Console.ReadLine();
- SortedDictionary<char, int> symbolCounter = new SortedDictionary<char, int>();
- foreach (char symbol in text)
- {
- if (!symbolCounter.ContainsKey(symbol))
- {
- symbolCounter[symbol] = 0;
- }
- symbolCounter[symbol]++;
- }
- foreach (var pair in symbolCounter)
- {
- Console.WriteLine("{0}: {1} time/s", pair.Key, pair.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement