Advertisement
LusienGG

[C#] Max Platform 3 x 3

Jun 2nd, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.Max_Platform_3_x_3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] pos = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             int rows = pos[0];
  15.             int cols = pos[1];
  16.             int[][] matrix = new int[rows][];
  17.             for (int i = 0; i < rows; i++)
  18.             {
  19.                 matrix[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  20.             }
  21.             long maxSum = int.MinValue;
  22.             int startRow = 0;
  23.             int startCol = 0;
  24.  
  25.             for (int i = 0; i < rows - 2; i++)
  26.             {
  27.                 for (int j = 0; j < cols - 2; j++)
  28.                 {
  29.  
  30.                     long sum = TmpSum(matrix, i, j);
  31.                     if (maxSum < sum)
  32.                     {
  33.                         maxSum = sum;
  34.                         startRow = i;
  35.                         startCol = j;
  36.                     }
  37.                 }
  38.             }
  39.             Console.WriteLine(maxSum);
  40.             for (int i = startRow; i < startRow + 3; i++)
  41.             {
  42.                 for (int j = startCol; j < startCol + 3; j++)
  43.                 {
  44.                     Console.Write(matrix[i][j] + " ");
  45.                 }
  46.                 Console.WriteLine();
  47.             }
  48.         }
  49.         static long TmpSum(int[][] matrix,int row,int col)
  50.         {
  51.             long sum = 0;
  52.             for (int tmpRow = row; tmpRow < row+3; tmpRow++)
  53.             {
  54.                 for (int tmpCol = col; tmpCol < col+3; tmpCol++)
  55.                 {
  56.                     sum += matrix[tmpRow][tmpCol];
  57.                 }
  58.             }
  59.             return sum;
  60.         }
  61.        
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement