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.PrintLettersCountInString
- {
- class Program
- {
- // 21. 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(string[] args)
- {
- Console.WriteLine("Insert text:");
- string text = Console.ReadLine();
- StringBuilder builder = new StringBuilder();
- StringBuilder count = new StringBuilder();
- for (int i = 0; i < text.Length; i++)
- {
- bool check = false;
- int position = 0;
- for (int j = 0; j < builder.Length; j++)
- {
- if (builder[j] == text[i])
- {
- check = true;
- position = j;
- break;
- }
- }
- if (check == false)
- {
- builder.Append(text[i]);
- count.Append(1);
- }
- else
- {
- count[position]++;
- }
- }
- //Console.WriteLine(string.Join(" ", builder.ToString()));
- //Console.WriteLine(string.Join(" ", count.ToString()));
- for (int i = 0; i < builder.Length; i++)
- {
- Console.WriteLine("Char: {0} Times: {1}" , builder[i], count[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement