Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- class Program
- {
- static List<string> variations = new List<string>();
- static int combLength;
- static void Main()
- {
- combLength = int.Parse(Console.ReadLine());
- string[] symbols = Console.ReadLine().Split(' ');
- char X = symbols[0][0];
- char Y = symbols[1][0];
- GenerateVariations("", X, Y);
- variations.Sort((x, y) => CustomSort(x, y));
- StringBuilder sb = new StringBuilder();
- foreach (var variation in variations)
- {
- sb.AppendLine(variation);
- }
- Console.WriteLine(sb.ToString());
- }
- private static int CustomSort(string x, string y)
- {
- for (int i = 0; i < x.Length; i++)
- {
- if (x[i] != y[i])
- {
- return x[i].CompareTo(y[i]);
- }
- }
- return x.CompareTo(y);
- }
- static void GenerateVariations(string current, char X, char Y)
- {
- if (current.Length == combLength)
- {
- variations.Add(current);
- return;
- }
- GenerateVariations(current + X, X, Y);
- GenerateVariations(current + Y, X, Y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement