Inheritance: Tokenizer
Exemple #1
0
        public static void Main()
        {
            var scanner       = new IO.Scanner();
            var numberOfSorts = scanner.NextInt();
            var result        = new List <string>();

            for (var i = 0; i < numberOfSorts; i++)
            {
                var numberOfPeople = scanner.NextInt();
                var people         = new List <Person>(numberOfPeople);

                for (var j = 0; j < numberOfPeople; j++)
                {
                    people.Add(Parse2(scanner.Next(), scanner.Next()));
                    scanner.Next();
                }

                result.AddRange(Sort(people));
                result.Add("==============================");
            }
            var outp = new IO.BufferedStdoutWriter();

            outp.WriteLine(string.Join(Environment.NewLine, result));
            outp.Flush();
            //Console.WriteLine(string.Join(Environment.NewLine, result));
        }
        public void Solve(Stream inStream, Stream outStream)
        {
            HashSet<Tuple<int, int>> cache = new HashSet<Tuple<int, int>>();
            Scanner scanner = new Scanner(inStream);
            StreamWriter writer = new StreamWriter(outStream);

            int metalsCount = scanner.NextInt();
            int experimentsCount = scanner.NextInt();

            if (experimentsCount < metalsCount - 1)
            {
                // not enough data to create unique order
                writer.WriteLine("back to the lab");
                writer.Flush();
                return;
            }

            if (metalsCount == 2)
            {
                // two metals - hadle it right away
                var result = SolutionFor2(scanner);
                writer.WriteLine(result);
                writer.Flush();
                return;
            }

            if (metalsCount == 1)
            {
                // one metal - solution is 0
                writer.WriteLine(0);
                writer.Flush();
                return;
            }

            for (int i = 0; i < experimentsCount; i++)
            {
                // read the experiment
                var a = scanner.NextInt();
                var b = scanner.NextInt();

                var rule = new Tuple<int, int>(a, b);

                cache.Add(rule);
            }

            var newResult = FindSolution(metalsCount, cache);

            writer.WriteLine(newResult == null ? "back to the lab" : string.Join(" ", newResult));
            writer.Flush();
        }
Exemple #3
0
        public void Solve(Stream inStream, Stream outStream)
        {
            Scanner scanner = new Scanner(inStream);

            StreamWriter writer = new StreamWriter(outStream);

            // read log size
            var logEntriesCount = scanner.NextInt();
            string name, result;

            for (int i = 0; i < logEntriesCount; i++)
            {
                var operation = scanner.Next();
                name = scanner.Next();

                if (operation == "entry")
                {
                    if (!accessLog.Contains(name))
                    {
                        // first entry
                        accessLog.Add(name);
                        result = Entry(false, name);
                    }
                    else
                    {
                        // already in the building
                        result = Entry(true, name);
                    }
                }
                else
                // exit
                {
                    if (accessLog.Contains(name))
                    {
                        accessLog.Remove(name);
                        result = Exit(false, name);
                    }
                    else
                    {
                        // not in the building but exiting
                        result = Exit(true, name);
                    }
                }

                writer.WriteLine(result);
            }

            writer.Flush();
        }
 private string SolutionFor2(Scanner scanner)
 {
     return scanner.Next() + " " + scanner.Next();
 }
Exemple #5
0
 public KattisSolver(Stream inStream, Stream outStream)
 {
     _scanner = new Scanner(inStream);
     _writer = new StreamWriter(outStream);
     _solver = new Solver();
 }