Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var U = new HashSet <string>();
            var A = new HashSet <string>();
            var B = new HashSet <string>();

            Console.Write("Элементы множества U: ");
            string[] strU = Console.ReadLine().Split(new char[] { ' ', '\n', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries);
            Console.Write("Элементы множества U без повторений: ");
            Hash(strU, U);

            foreach (string el in U)
            {
                Console.Write(el + " ");
            }

            Console.Write("\nЭлементы множества A: ");
            string[] strA = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            Console.Write("Готовое множество A: ");
            Hash(strA, A);
            A.IntersectWith(U);
            foreach (string el in A)
            {
                Console.Write(el + " ");
            }

            Console.Write("\nЭлементы множества B: ");
            string[] strB = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            Console.Write("Готовое множество B : ");
            Hash(strB, B);
            B.IntersectWith(U);
            foreach (string el in B)
            {
                Console.Write(el + " ");
            }
            Array.Resize(ref strA, U.Count);
            Array.Resize(ref strB, U.Count);

            BitArray bitU = new BitArray(U.Count);
            BitArray bitA = new BitArray(strA.Length);
            BitArray bitB = new BitArray(strB.Length);

            update(bitU, bitA, U, strA);
            update(bitU, bitB, U, strB);

            BitArray or = LogicalOperations.Or(bitA, bitB);

            Console.Write("Объединение АВ: ");
            writeString(or, U);

            update(bitU, bitA, U, strA);
            update(bitU, bitB, U, strB);

            BitArray and = LogicalOperations.And(bitA, bitB);

            Console.Write("Пересечение АВ: ");
            writeString(and, U);

            update(bitU, bitA, U, strA);
            update(bitU, bitB, U, strB);

            BitArray not = LogicalOperations.Not(bitA);

            Console.Write("Дополнение А: ");
            writeString(not, U);

            update(bitU, bitA, U, strA);
            update(bitU, bitB, U, strB);


            BitArray diff = LogicalOperations.Dif(bitA, bitB);

            Console.Write("Разность А/В: ");
            writeString(diff, U);
            Console.WriteLine();

            bool con = false;

            Console.WriteLine("Пункт 2");
            while (con == false)
            {
                Console.WriteLine("Выберете задние 1,2 или 3");
                int n = Int32.Parse(Console.ReadLine());
                switch (n)
                {
                case 1:
                    getFirst();
                    con = true;
                    break;

                case 2:
                    getSecond();
                    con = true;
                    break;

                case 3:
                    getThird();
                    con = true;
                    break;

                default:
                    Console.WriteLine("Вы точно выбрали ту цифру?");
                    break;
                }
            }
        }