public void Solve()
            {
                string nextLine;
                var    regexPattern =
                    Stex.Begin +
                    "Disc #" +
                    Stex.Integer("Index") +
                    " has " +
                    Stex.Integer("Positions") +
                    " positions; at time=0, it is at position " +
                    Stex.Integer("Start") +
                    "." +
                    Stex.End;
                var rgx = new Regex(regexPattern);

                var a    = new List <long>();
                var mods = new List <long>();

                while ((nextLine = ReadLine()) != null)
                {
                    var match = rgx.Match(nextLine);
                    var index = int.Parse(match.Groups["Index"].Value);
                    var mod   = int.Parse(match.Groups["Positions"].Value);
                    var start = int.Parse(match.Groups["Start"].Value);
                    a.Add((100 * mod - start - index) % mod);
                    mods.Add(mod);
                }
                WriteLine(ChineseRemainder.CRT(a.ToArray(), mods.ToArray()));
                a.Add(11 - a.Count - 1);
                mods.Add(11);
                WriteLine(ChineseRemainder.CRT(a.ToArray(), mods.ToArray()));
            }
示例#2
0
        static HeaderInfo()
        {
            // Set up the regular expression to read the header
            var signature      = Stex.Any.Rep(5, 5).Named("Signature");
            var hardBlank      = ".".Named("HardBlank");
            var height         = Stex.Integer().Named("Height");
            var baseline       = Stex.Integer().Named("Baseline");
            var maxLength      = Stex.Integer().Named("MaxLength");
            var oldLayout      = Stex.Integer().Named("OldLayout");
            var commentLines   = Stex.Integer().Named("CommentLines");
            var printDirection = Stex.Integer().Named("PrintDirection");
            var fullLayout     = Stex.Integer().Named("FullLayout");
            var codetagCount   = Stex.Integer().Named("CodetagCount");
            var sep            = Stex.WhitePadding;
            var optionalParams = Stex.Cat(sep, printDirection, sep, fullLayout, sep, codetagCount).Optional();
            var rgx            = Stex.Cat(
                signature,
                hardBlank, sep,
                height, sep,
                baseline, sep,
                maxLength, sep,
                oldLayout, sep,
                commentLines,
                optionalParams);

            RgxHeader = new Regex(rgx, RegexOptions.Compiled);
        }
示例#3
0
        static CharInfo()
        {
            // Create the regular expression for reading codetags
            var neg   = "-".Optional();
            var octal = Stex.Cat("0", Stex.Range("0", "7").Rep(1)).Named("Octal");
            var hex   = Stex.Cat("0",
                                 Stex.AnyCharFrom("Xx"),
                                 Stex.AnyCharFrom("A-Fa-f0-9").Rep(1)).Named("Hex");
            var code        = neg + Stex.AnyOf(octal, hex, Stex.Integer("Decimal")).Named("Code");
            var codeTagExpr = code + Stex.WhitePadding + Stex.Any.Rep(1).Named("Comment");

            RgxCodeTag = new Regex(codeTagExpr, RegexOptions.Compiled);
        }