SetIn() public static méthode

public static SetIn ( System newIn ) : void
newIn System
Résultat void
Exemple #1
0
 public static void MainTest(string[] args)
 {
     if (args.Length > 0)
     {
         StdIn.SetIn(File.OpenText(args[0]));
     }
     Console.WriteLine("Template");
 }
Exemple #2
0
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }
            int    n = Int32.Parse(StdIn.ReadLine());
            double r = StdEv(ReadAllInts(StdIn.ReadLine()));

            Console.WriteLine($"{r:F1}");
        }
Exemple #3
0
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }

            ReadInt();
            int[]  arr = ReadAllInts();
            int    n = arr.Length / 2;
            double q1 = Median(arr, 0, n), q2 = Median(arr, 0, arr.Length), q3 = Median(arr, n + arr.Length % 2, n);

            Console.WriteLine("{0:#.##}\n{1:#.##}\n{2:#.##}", q1, q2, q3);
        }
Exemple #4
0
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }
            int[]        n       = ReadInts();
            List <int[]> queries = new List <int[]>();

            while (n[1]-- > 0)
            {
                queries.Add(ReadInts());
            }
            GetDynamicArray(n[0], queries, (a) => Console.WriteLine(a));
        }
Exemple #5
0
        public Stream Redirect(TextReader reader, Action action)
        {
            if (reader == null)
            {
                return(Redirect(action));
            }
            var    standardIn = SysConsole.In;
            Stream result     = null;

            SysConsole.SetIn(reader);

            result = Redirect(action);

            SysConsole.SetIn(standardIn);
            return(result);
        }
Exemple #6
0
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }
            int n = Int32.Parse(StdIn.ReadLine());

            int[] s  = ReadAllInts(StdIn.ReadLine(), n), w = ReadAllInts(StdIn.ReadLine(), n);
            float wm = 0;
            float wt = 0;

            for (int i = 0; i < n; i++)
            {
                wm += s[i] * w[i];
                wt += w[i];
            }
            Console.WriteLine($"{wm / wt:F1}");
        }
Exemple #7
0
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }
            int t = NextInt();

            while (t-- > 0)
            {
                int n    = NextInt();
                var list = new DoublyLinkedList();
                while (n-- > 0)
                {
                    list.InsertNode(NextInt());
                }
                list.head.SortedInsert(NextInt());
                list.PrintDoublyLinkedList(" ", Console.Out);
            }
        }
Exemple #8
0
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }
            int[] d1 = new int[] { 1, 2, 3, 4, 5, 6 }, d2 = new int[] { 1, 2, 3, 4, 5, 6 };
            int   k  = 1;

            for (int i = 0; i < d1.Length; i++)
            {
                for (int j = 0; j < d2.Length; j++)
                {
                    if ((d1[i]) % 2 == 1 && (d2[j] % 2 == 1))
                    {
                        Console.WriteLine($"{k++} : [{d1[i]}, {d2[j]}]");
                    }
                }
            }
            //Console.WriteLine("{k}/36");
        }
Exemple #9
0
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }
            int n = NextInt();

            int[] x = ReadAllInts(), f = ReadAllInts();
            int[] s = new int[f.Sum()];
            for (int i = 0, k = 0; i < x.Length; i++)
            {
                for (int j = 0; j < f[i]; j++)
                {
                    s[k++] = x[i];
                }
            }
            Array.Sort(s);
            int    hi = s.Length / 2;
            double q1 = Median(s, 0, hi), q3 = Median(s, hi + s.Length % 2, hi);

            Console.WriteLine($"{(q3 - q1):F1}");
        }
        public static void MainTest(string[] args)
        {
            if (args.Length > 0)
            {
                StdIn.SetIn(File.OpenText(args[0]));
            }
            int t = NextInt(), n = NextInt();
            SinglyLinkedList list = new SinglyLinkedList();

            while (n-- > 0)
            {
                list.InsertNode(NextInt());
            }

            StringBuilder sb      = new StringBuilder();
            var           cur     = RemoveDuplicates(list.head);

            while (cur != null)
            {
                sb.Append(sb.Length > 0 ? $" {cur.data}" : cur.data);
                cur = cur.next;
            }
            Console.WriteLine(sb);
        }
Exemple #11
0
        public void StandardIOComplies()
        {
            #region In, Out, Error
            // Assert.
            Assert.Same(Base.In, Facade.In);
            Assert.Same(Base.Out, Facade.Out);
            Assert.Same(Base.Error, Facade.Error);
            #endregion

            #region SetIn, SetOut, SetError
            // Base/Facade
            // Act.
            Base.SetIn(TestIn);
            Base.SetOut(TestOut);
            Base.SetError(TestError);

            // Assert.
            Assert.Same(Base.In, Facade.In);
            Assert.Same(Base.Out, Facade.Out);
            Assert.Same(Base.Error, Facade.Error);

            // Teardown.
            Base.SetIn(BaseIn);
            Base.SetOut(BaseOut);
            Base.SetError(BaseError);

            // Facade/Base
            // Act.
            Facade.SetIn(TestIn);
            Facade.SetOut(TestOut);
            Facade.SetError(TestError);

            // Assert.
            Assert.Same(Facade.In, Base.In);
            Assert.Same(Facade.Out, Base.Out);
            Assert.Same(Facade.Error, Base.Error);
            #endregion

            #region WriteLine, ReadLine, Clear
            // Base/Facade
            // Act.
            Base.WriteLine("Hello, world!");

            // Assert.
            TestStream.Position = 0;
            Assert.Equal("Hello, world!", Facade.ReadLine());

            // Act.
            Base.Clear();

            // Assert.
            Assert.Equal(string.Empty, Facade.ReadLine());

            // Facade/Base
            // Act.
            Facade.WriteLine("Hello, world!");

            // Assert.
            TestStream.Position = 0;
            Assert.Equal("Hello, world!", Base.ReadLine());

            // Act.
            Facade.Clear();

            // Assert.
            Assert.Equal(string.Empty, Base.ReadLine());
            #endregion

            #region Teardown
            // Act.
            Base.SetIn(BaseIn);
            Base.SetOut(BaseOut);
            Base.SetError(BaseError);

            // Assert.
            Assert.Same(BaseIn, Facade.In);
            Assert.Same(BaseOut, Facade.Out);
            Assert.Same(BaseError, Facade.Error);
            #endregion
        }