Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- namespace BOunce
- {
- class Program
- {
- static void Main(string[] args)
- {
- //initialize
- int[] input = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
- int rows = input[0];
- int cols = input[1];
- int[,] matrix = new int[rows, cols];
- //fill matrix
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = (int)Math.Pow(2, (col + row));
- }
- }
- //sum numbers in matrix & bounce
- int dirX = 1;
- int dirY = 1;
- int x = 1;
- int y = 1;
- int sum = 1;
- if (rows == 1 || cols == 1)
- {
- Console.WriteLine(1);
- }
- else
- {
- while (true)
- {
- sum += matrix[x, y];
- if ((x == rows - 1) && (y == cols - 1)) break;
- else if ((x == 0) && (y == 0)) break;
- else if ((x == rows - 1) && (y == 0)) break;
- else if ((x == 0) && (y == cols - 1)) break;
- if (x == 0 || x == (rows - 1))
- {
- dirX *= -1;
- }
- else if (y == 0 || y == (cols - 1))
- {
- dirY *= -1;
- }
- x += dirX;
- y += dirY;
- }
- Console.WriteLine(sum);
- }
- //print matrix
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- Console.Write(matrix[row, col] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement