Beispiel #1
0
        //public static void Main(string[] args)
        //{
        //    string s;
        //    var inputs = new List<string>();
        //    while ((s = Console.ReadLine()) != null)
        //        inputs.Add(s);

        //    foreach (var result in Answer(inputs.ToArray()))
        //        Console.WriteLine(result);
        //}

        public static IList <string> Answer(IList <string> inputs)
        {
            var addList = new List <Tuple <int, int, char> >();
            Action <int, int, char> addLogger = (x, y, c) => addList.Add(new Tuple <int, int, char>(x, y, c));

            var builder = new PrefixTree <char> .Builder(inputs);

            var n = builder.NextAsInt();

            builder.ToTrie(n, new NucleotidePrefixTreeContext(), addLogger);

            var answers = addList.Select(t => string.Format("{0}->{1}:{2}", t.Item1, t.Item2, t.Item3)).ToArray();

            return(answers);
        }
        //public static void Main(string[] args)
        //{
        //    string s;
        //    var inputs = new List<string>();
        //    while ((s = Console.ReadLine()) != null)
        //        inputs.Add(s);

        //    foreach (var result in Answer(inputs.ToArray()))
        //        Console.WriteLine(result);
        //}

        public static IList <string> Answer(IList <string> inputs)
        {
            var builder = new PrefixTree <char> .Builder(inputs);

            var text = builder.NextAsString();
            var n    = builder.NextAsInt();
            var trie = builder.ToTrie(n, new NucleotidePrefixTreeContext());

            var matcheIndexes = Enumerable.Range(0, text.Length)
                                .Where(i =>
            {
                var t     = text.Substring(i);
                var match = trie.Match(t);
                Console.WriteLine("{0} {1} {2}", match, i, t);
                return(match);
            })
                                .Select(i => i.ToString());

            return(new [] { string.Join(" ", matcheIndexes) });
        }