예제 #1
0
        private static bool IsInRange(MatrixCoordinates size, int row, int col)
        {
            bool rowIsInRange = row > -1 && row < size.Row;
            bool colIsInRange = col > -1 && col < size.Col;

            return rowIsInRange && colIsInRange;
        }
예제 #2
0
        private static void TraverseField(MatrixCoordinates size, bool[,] field, int directionChangesCount)
        {
            MatrixCoordinates position = new MatrixCoordinates(field.GetLength(0) - 1, 0);

            field[position.Row, position.Col] = true;

            for (int i = 0; i < directionChangesCount; i++)
            {
                string[] command = GetCommand();
                int      moves   = int.Parse(command[1]);

                MatrixCoordinates dirChange = GetDirChange(command[0]);

                for (int move = 0; move < moves - 1; move++)
                {
                    if (!IsInRange(size, position.Row + dirChange.Row, position.Col + dirChange.Col))
                    {
                        break;
                    }

                    position.Row += dirChange.Row;
                    position.Col += dirChange.Col;

                    field[position.Row, position.Col] = true;
                }
            }
        }
예제 #3
0
        private static bool IsInRange(MatrixCoordinates size, int row, int col)
        {
            bool rowIsInRange = row > -1 && row < size.Row;
            bool colIsInRange = col > -1 && col < size.Col;

            return(rowIsInRange && colIsInRange);
        }
예제 #4
0
        internal static void Main()
        {
            MatrixCoordinates dimensions = GetDimensions();

            bool[,] field = new bool[dimensions.Row, dimensions.Col];
            int directionChangesCount = int.Parse(Console.ReadLine());

            TraverseField(dimensions, field, directionChangesCount);

            long result = GetSum(field);

            Console.WriteLine(result);
        }
예제 #5
0
        private static void TraverseField(MatrixCoordinates size, bool[,] field, int directionChangesCount)
        {
            MatrixCoordinates position = new MatrixCoordinates(field.GetLength(0) - 1, 0);

            field[position.Row, position.Col] = true;

            for (int i = 0; i < directionChangesCount; i++)
            {
                string[] command = GetCommand();
                int moves = int.Parse(command[1]);

                MatrixCoordinates dirChange = GetDirChange(command[0]);

                for (int move = 0; move < moves - 1; move++)
                {
                    if (!IsInRange(size, position.Row + dirChange.Row, position.Col + dirChange.Col))
                    {
                        break;
                    }

                    position.Row += dirChange.Row;
                    position.Col += dirChange.Col;

                    field[position.Row, position.Col] = true;
                }
            }
        }