コード例 #1
0
        public static void Main(string[] args)
        {
            int[] whitelist = new In(args[0]).ReadAllInts();

            Array.Sort(whitelist);

            // read key; print if not in whitelist
            while (!StdIn.IsEmpty())
            {
                int key = StdIn.ReadInt();
                
                if (Rank(key, whitelist) == -1)
                {
                    Console.WriteLine(key);
                }
            }
        }
コード例 #2
0
ファイル: In.cs プロジェクト: kostasgrevenitis/algs4
        /// <summary>
        /// Test client
        /// </summary>
        public static void Main(string[] args)
        {
            In input;

            // read one line at a time from file in current directory
            Console.WriteLine("ReadLine() from current directory");
            Console.WriteLine("---------------------------------------------------------------------------");

            try
            {
                input = new In(args[0]);

                while (!input.IsEmpty())
                {
                    String s = input.ReadLine();
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine();

            // read one char at a time
            Console.WriteLine("ReadChar() from file");
            Console.WriteLine("---------------------------------------------------------------------------");

            try
            {
                input = new In(args[0]);

                while (!input.IsEmpty())
                {
                    char c = input.ReadChar();
                    Console.Write(c);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("End");
            Console.ReadKey();
        }