Exemplo n.º 1
0
        //Proccess the data file.
        int[,] ProcessDataFile(InFile data)
        {
            int[,] board = new int[9, 9];
            int rows = 0;
            int cols = 0;

            while (!data.NoMoreData())
            {
                if (rows == 9)
                {
                    break;
                }
                board[rows, cols] = data.ReadInt();
                //incrementing cols & rows
                if (cols == 8)
                {
                    cols = 0;
                    rows++;
                }
                else
                {
                    cols++;
                }
            }
            return(board);
        }
Exemplo n.º 2
0
    public static void Main(string[] args)
    {
        //                                        check that arguments have been supplied
        if (args.Length != 2)
        {
            Console.WriteLine("missing args");
            System.Environment.Exit(1);
        }
        //                                        attempt to open data file
        InFile data = new InFile(args[0]);

        if (data.OpenError())
        {
            Console.WriteLine("cannot open " + args[0]);
            System.Environment.Exit(1);
        }
        //                                        attempt to open results file
        OutFile results = new OutFile(args[1]);

        if (results.OpenError())
        {
            Console.WriteLine("cannot open " + args[1]);
            System.Environment.Exit(1);
        }
        //                                        various initializations
        int    total       = 0;
        IntSet mySet       = new IntSet();
        IntSet smallSet    = new IntSet(1, 2, 3, 4, 5);
        string smallSetStr = smallSet.ToString();
        //                                        read and process data file
        int item = data.ReadInt();

        while (!data.NoMoreData())
        {
            total = total + item;
            if (item > 0)
            {
                mySet.Incl(item);
            }
            item = data.ReadInt();
        }
        //                                        write various results to output file
        results.Write("total = ");
        results.WriteLine(total, 5);
        results.WriteLine("unique positive numbers " + mySet.ToString());
        results.WriteLine("union with " + smallSetStr
                          + " = " + mySet.Union(smallSet).ToString());
        results.WriteLine("intersection with " + smallSetStr
                          + " = " + mySet.Intersection(smallSet).ToString());

        /* or simply
         * results.WriteLine("union with " + smallSetStr + " = " + mySet.Union(smallSet));
         * results.WriteLine("intersection with " + smallSetStr + " = " + mySet.Intersection(smallSet));
         */

        results.Close();
    } // Main
Exemplo n.º 3
0
        static void readBoard(string[,] board, int[, ][,] suggestedBoard, InFile data, bool solution)
        {
            int row = 0, col = 0;

            while (row != 9 && !data.NoMoreData())
            {
                int num = data.ReadInt();

                if (num == 0)
                {
                    board[row, col] = "..";
                    if (!solution)
                    {
                        suggestedBoard[row, col] = new int[3, 3] {
                            { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
                        };
                    }
                }
                else
                {
                    board[row, col] = " " + num;
                    if (!solution)
                    {
                        suggestedBoard[row, col] = null;
                        known++;
                    }
                }
                col++;
                if (col == 9)
                {
                    row++;
                    col = 0;
                }
            }

            /*if the board just filled was not the solution then
             * skip next three lines to get to the next board (which is the solution board)*/
            if (!solution)
            {
                data.ReadLine();
                data.ReadLine();
                data.ReadLine();
            }
        }