using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lerochka
{
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 t = "";
foreach (Symbol x in symbols)
{
t += "(" + x.Value + ":" + x.Count + ") ";
}
return t;
}
}
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 chisl = 0;
int znam = 1;
for (int i = 0; i < symbols.Length; i++)
{
chisl += symbols[i].Count;
znam *= Factorial(symbols[i].Count);
}
chisl = Factorial(chisl);
return chisl / znam;
}
static void Main(string[] args)
{
Console.Write("Введите исходный текст: ");
string text = Console.ReadLine();
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("Элементы строки в виде (элемент:количество): " + symbols.ToString());
Console.WriteLine("Количество возможных перестановок с повторениями = " + Perestanovki_s_Povt(symbols.symbols));
Console.ReadLine();
}
}
}