Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- class MessageInBottle
- {
- static void Main()
- {
- string inputNumbersString = "1122";
- string textToDecode = "A1B12C11D2";
- mainArrChars = new List<char>();
- mainArrNumbs = new List<string>();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < textToDecode.Length; i++)
- {
- int currentCharValue = (int)textToDecode[i];
- if (currentCharValue >= 65 && currentCharValue <= 90)
- {
- mainArrNumbs.Add(sb.ToString());
- mainArrChars.Add((char)currentCharValue);
- sb = new StringBuilder();
- }
- else
- {
- sb.Append((char)currentCharValue);
- }
- }
- mainArrNumbs.Add(sb.ToString());
- CalculateCodes(inputNumbersString, "");
- Print();
- }
- static List<string> mainArrNumbs = new List<string>();
- static List<char> mainArrChars;
- static List<string> finalOutput = new List<string>();
- static void Print(string[] vector)
- {
- for (int i = 0; i < vector.Length; i++)
- {
- Console.Write("{0} ",vector[i]);
- }
- Console.WriteLine();
- }
- static void CalculateCodes(string currentCode, string codeInQueue)
- {
- if (currentCode.Length == 0)
- {
- finalOutput.Add(codeInQueue);
- return;
- }
- for (int i = 1; i < mainArrNumbs.Count ; i++)
- {
- if (currentCode.StartsWith(mainArrNumbs[i]))
- {
- CalculateCodes(currentCode.Substring(mainArrNumbs[i].Length) , codeInQueue + mainArrChars[i - 1]);
- }
- }
- }
- static void Print()
- {
- Console.WriteLine(finalOutput.Count);
- finalOutput.Sort();
- foreach (string comb in finalOutput)
- {
- Console.WriteLine(comb);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement