Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Cipher
- {
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main(string[] args)
- {
- string secretMessage = Console.ReadLine();
- string cipher = Console.ReadLine();
- Dictionary<string, string> cipherDict = new Dictionary<string, string>();
- List<List<string>> dp = new List<List<string>>();
- for (int i = 0; i < cipher.Length; i++)
- {
- char letter = cipher[i];
- i++;
- string code = "";
- while (i < cipher.Length && char.IsDigit(cipher[i]))
- {
- code += cipher[i];
- i++;
- }
- cipherDict[code] = letter.ToString();
- i--;
- }
- for (int i = 0; i <= secretMessage.Length; i++)
- {
- dp.Add(new List<string>());
- }
- dp[0].Add("");
- for (int i = 0; i < secretMessage.Length; i++)
- {
- for (int j = i + 1; j <= secretMessage.Length; j++)
- {
- string subStr = secretMessage.Substring(i, j - i);
- if (cipherDict.ContainsKey(subStr))
- {
- foreach (var str in dp[i])
- {
- dp[j].Add(str + cipherDict[subStr]);
- }
- }
- }
- }
- Console.WriteLine(dp[secretMessage.Length].Count);
- dp[secretMessage.Length].Sort();
- foreach (string result in dp[secretMessage.Length])
- {
- Console.WriteLine(result);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement