Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _1.MessageInABottle
- {
- struct Particle
- {
- public Particle(char letter, string code) : this()
- {
- Letter = letter;
- Code = code;
- }
- public char Letter { get; set; }
- public string Code { get; set; }
- }
- class Program
- {
- static List<Particle> particles = new List<Particle>();
- static List<string> results = new List<string>();
- private static char letter;
- private static string secretCode;
- static void Main()
- {
- secretCode = Console.ReadLine();
- string cipher = Console.ReadLine();
- StringBuilder code = new StringBuilder();
- for (int i = 0; i < cipher.Length; i++)
- {
- if (cipher[i] >= 'A' && cipher[i] <= 'Z')
- {
- if (i != 0)
- {
- particles.Add(new Particle(letter, code.ToString()));
- code.Clear();
- }
- letter = cipher[i];
- }
- else
- {
- code.Append(cipher[i]);
- }
- }
- particles.Add(new Particle(letter, code.ToString()));
- Recursion(0);
- Console.WriteLine(results.Count);
- results.Sort();
- foreach (string result in results)
- {
- Console.WriteLine(result);
- }
- }
- static StringBuilder currentResult = new StringBuilder();
- private static void Recursion(int secretCodeIndex)
- {
- if (secretCodeIndex >= secretCode.Length)
- {
- results.Add(currentResult.ToString());
- return;
- }
- foreach (Particle particle in particles)
- {
- if (secretCode.Substring(secretCodeIndex).StartsWith(particle.Code))
- {
- currentResult.Append(particle.Letter);
- Recursion(secretCodeIndex + particle.Code.Length);
- currentResult.Remove(currentResult.Length - 1, 1);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement