Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Task2
- {
- public class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите строку: ");
- string input = Console.ReadLine() ?? string.Empty; // защита от null
- int uniqueCount = CountUniqueChars(input);
- Console.WriteLine($"Количество уникальных символов в строке \"{input}\": {uniqueCount}");
- }
- public static int CountUniqueChars(string word)
- {
- if (string.IsNullOrEmpty(word))
- return 0;
- HashSet<char> uniqueChars = new HashSet<char>();
- foreach (char ch in word)
- {
- uniqueChars.Add(ch);
- }
- return uniqueChars.Count;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement