Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _21.PrintDiferentLetters
- {
- class PrintDiferentLetters
- {
- /* Write a program that reads a string from the
- * console and prints all different letters in the
- * string along with information how many times each
- * letter is found.*/
- static void Main()
- {
- Console.Write("Please enteyr string : ");
- string inputString = Console.ReadLine().ToLower();
- string letters = "abcdefghijklmnopqrstuvwxyzABCDEFJHIGKLMNOPQRSTUVWXYZ";
- List<char> chars = new List<char>();
- List<int> counts = new List<int>();
- for (int i = 0; i < inputString.Length; i++)
- {
- int count = 0;
- if (letters.Contains(inputString[i] ))
- {
- count = inputString.Split(inputString[i]).Length - 1;
- }
- else
- {
- continue;
- }
- if (count != 0)
- {
- chars.Add(inputString[i]) ;
- counts.Add(count);
- inputString = inputString.Replace(inputString[i], ' ');
- }
- }
- for (int i = 0; i < chars.Count; i++)
- {
- Console.WriteLine("{0} --> {1}", chars[i], counts[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement