Example #1
0
        protected override string Solve(string input)
        {
            if (input.Contains("()"))
            {
                throw new Exception();                                   //does not handle empty case
            }
            CodeJamIO io  = new CodeJamIO(input);
            var       val = io.GetSpaceSplit(0);
            int       L   = int.Parse(val[0]);
            int       D   = int.Parse(val[1]);
            int       N   = int.Parse(val[2]);

            int           i    = 1;
            List <string> look = new List <string>();

            for (var j = 0; j < D; j++, i++)
            {
                var word = io[i];
                if (word.Length != L)
                {
                    throw new Exception();
                }
                look.Add(word);
            }

            for (int j = 0; j < N; j++, i++)
            {
                var str     = io[i];
                var matches = System.Text.RegularExpressions.Regex.Matches(str, @"\([a-z]+\)|[a-z]");
                if (matches.Count != L)
                {
                    throw new Exception();
                }
                var v = from m in matches.Cast <System.Text.RegularExpressions.Match>()
                        select m.Value.Replace("(", "").Replace(")", "");

                var chars = v.ToArray();

                int cnt = 0;
                //Solve it here
                foreach (var s in look)
                {
                    bool good = true;
                    for (int k = 0; k < s.Length; k++)
                    {
                        char cur = s[k];
                        if (!chars[k].Contains(cur))
                        {
                            good = false;
                            break;
                        }
                    }

                    if (good)
                    {
                        cnt++;
                    }
                }

                io.WriteCase(cnt.ToString());
            }

            return(io.GetResults());
        }
Example #2
0
        protected override string Solve(string input)
        {
            CodeJamIO io   = new CodeJamIO(input);
            int       la   = int.Parse(io[0]);
            int       line = 1;

            for (int map = 0; map < la; map++)
            {
                int height = int.Parse(io.GetSpaceSplit(line)[0]);
                int width  = int.Parse(io.GetSpaceSplit(line)[1]);
                line++;

                int[,] alt = new int[height, width];
                N[,] stuff = new N[height, width];
                for (int h = 0; h < height; h++, line++)
                {
                    var l = io.GetSpaceSplit(line);
                    if (l.Length != width)
                    {
                        throw new Exception();
                    }
                    for (int w = 0; w < l.Length; w++)
                    {
                        alt[h, w]   = int.Parse(l[w]);
                        stuff[h, w] = new N();
                    }
                }

                for (int h = 0; h < height; h++)
                {
                    for (int w = 0; w < width; w++)
                    {
                        PutChild(stuff, h, w, alt);
                    }
                }

                StringBuilder sb = new StringBuilder();
                sb.AppendLine();

                char ch = 'a';
                for (int h = 0; h < height; h++)
                {
                    for (int w = 0; w < width; w++)
                    {
                        N n = stuff[h, w];
                        while (n.child != null)
                        {
                            n = n.child;
                        }

                        if (n.ch == '7')
                        {
                            n.ch = ch;
                            ch++;
                        }

                        sb.Append(n.ch);
                        sb.Append(' ');
                    }
                    sb.AppendLine();
                }

                sb.Length = sb.Length - 2;
                io.WriteCase(sb.ToString());
            }

            return(io.GetResults());
        }