https://pastein.ru/t/we

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


using System;

namespace HWMAth
{

    class ObjectTypes
    {
        private int count;
        private string[] types;
        private int[] koltype;
        private int n;

        public ObjectTypes(string str)
        {
            string[] words = str.Split(' ');           
            types = new string[words.Length];
            koltype = new int[words.Length];
            count = 0;
            n = words.Length;
            Add(words);
        }

        private void Add(string[] words)
        {
            for (int i = 0; i < words.Length; i++)
            {
                if (words[i] == "")
                {
                    n--;
                    continue;
                }
                bool b = NotExist(words[i]);
                if (b)
                {
                    types[count] = words[i];
                    koltype[count] = 1;
                    count++;

                }
            }

        }
        private bool NotExist(string word)
        {
            for (int i = 0; i < count; i++)
            {
                if (types[i] == word)
                {

                    koltype[i]++;                   
                    return false;
                }
            }
            return true;
        }


        public int perestan()
        {
            int res = 1;            
            int znam = 1;
            for (int i = 0; i < count; i++)
            {
                znam *= factorial(koltype[i]);
            }
            res = factorial(n) / znam;
            Console.WriteLine($"Количество перестановок с повторениями - {res}");
            return res;
        }

        private int factorial(int k)
        {
            int res =1;
            for (int i = 1; i < k+1; i++)
            {
                res = res * i;
            }
            return res;
        }


        public override string ToString()
        {
            string t = @$"Всего элементов - {n}
";
            for (int i = 0; i < count; i++)
            {
                t += $"( нахвание {i + 1} типа - " + types[i] + $"; кол-во элементов {i + 1} типа - " + koltype[i] + ") " + @"
";
            }

            return t;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {

            string text = Console.ReadLine();
            ObjectTypes p1 = new ObjectTypes(text);
            Console.WriteLine(p1);
            Console.WriteLine();
            Console.WriteLine();
            p1.perestan();
            Console.ReadKey();
            //1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
            //red red red blue blue red red black blue black

        }
    }
}