using System; using System.Collections; public class Operaciones { public static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine(@"BAD USAGE: mono Alfabeto.exe potencia alfabeto,separado,por,comas"); return; } int Potencia = int.Parse(args[0]); string[] elementos = args[1].Split(','); Alfabeto alfabeto = new Alfabeto(); foreach(string elemento in elementos) alfabeto.Add(new Elemento(elemento)); Alfabeto resultado = Alfabeto.Pow(alfabeto, Potencia); for (int i = 0; i < resultado.Count; i++) Console.Write(resultado[i].Value + ","); Console.WriteLine(); } } public class Alfabeto { ArrayList Elementos = new ArrayList(); public void Add(Elemento Item) { Elementos.Add(Item); } public int Count { get { return Elementos.Count; } } public Elemento this [int index] { get { return Elementos[index] as Elemento; } } public Alfabeto Clone() { Alfabeto clon = new Alfabeto(); foreach(Elemento Item in Elementos) clon.Add(new Elemento(Item.Value)); return clon; } public static Alfabeto operator* (Alfabeto Factor1, Alfabeto Factor2) { Alfabeto resultado = new Alfabeto(); for (int i = 0; i < Factor1.Count; i++) for (int j = 0; j < Factor2.Count; j++) { resultado.Add(new Elemento(Factor1[i].Value + Factor2[j].Value)); } return resultado; } public static Alfabeto Pow(Alfabeto Base, int Potencia) { if (Potencia < 0) throw new Exception("No se permiten potencias negativas"); else if (Potencia == 0) return new Alfabeto(); else if (Potencia == 1) return Base.Clone(); else { Alfabeto Resultado = Base.Clone(); for (int i = 0; i < Potencia - 1; i++) { Resultado *= Base; } return Resultado; } } } public class Elemento { string valor; public Elemento(string Value) { valor = Value; } public string Value { get { return valor; } set { valor = value; } } }