https://pastein.ru/t/Pe

  скопируйте уникальную ссылку для отправки


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discret
{
    public class Symbol
    {
        public Symbol (char value)
        {
            this.Value = value;
            this.Count = 1;
        }
        public char Value { get; set; }
        public int Count { get; set; }
    }
    
    public class Symbols
    {
        public Symbol[] symbols;
        private int count;
        public Symbols()
        {
            this.symbols = new Symbol[0];
            this.count = 0;
        }
        public void Add(Symbol symbol)
        {
            Symbol[] symbols_ = new Symbol[symbols.Length + 1];
            Array.Copy(symbols, symbols_, symbols.Length);
            symbols = symbols_;
            symbols[count++] = symbol;
        }
        public bool Find(char x)
        {
            if (symbols.Length == 0)
            {
                return false;
            }
            else if (Array.Exists(symbols, elem => elem.Value == x))
            {
                return true;
            }
            else return false;
        }
        public int Index(char x)
        {
            int t = 0;
            foreach (Symbol temp in symbols)
            {
                if (temp.Value.Equals(x))
                {
                    return t;
                }
                t++;
            }
            return -1;
        }
        public void CountUp(int index)
        {
            symbols[index].Count++;
        }
        public override string ToString()
        {
            string output = "";
            foreach (Symbol x in symbols)
            {
                output += $"[{x.Value}:{x.Count}] ";
            }
            return output;
        }
    }
    class Program
    {
        static int Factorial(int a)
        {
            int count = 1;
            int aFact = 1;
            while (count <= a)
            {
                aFact = aFact * count;
                count++;
            }
            return aFact;
        }
        static int Perestanovki_s_Povt(Symbol[] symbols)
        {
            int up = 0;
            int down = 1;
            for (int i = 0; i < symbols.Length; i++)
            {
                up += symbols[i].Count;
                down *= Factorial(symbols[i].Count);
            }
            up = Factorial(up);
            return up / down;
        }
        static void Main(string[] args)
        {
            string path = "D:\\Projects\\for_Discret.txt";
            FileStream file = new FileStream(path, FileMode.Open); //создаем файловый поток
            StreamReader reader = new StreamReader(file); // создаем «потоковый читатель» и связываем его с файловым потоком
            string text = reader.ReadToEnd(); //считываем все данные с потока и записываем в переменную
            reader.Close(); //закрываем поток
            Symbols symbols = new Symbols();
            foreach (char x in text)
            {
                if (symbols.Find(x))
                {
                    symbols.CountUp(symbols.Index(x));
                }
                else
                {
                    symbols.Add(new Symbol(x));
                }
            }
            Console.WriteLine($"Исходная строка: {text}");
            Console.WriteLine($"Элементы строки в виде [элемент:количество]: {symbols.ToString()}");
            Console.WriteLine($"Количество возможных перестановок с повторениями = {Perestanovki_s_Povt(symbols.symbols)}");
            Console.ReadLine();
        }
    }
}