Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleTesting3
- {
- class ConsoleTesting3
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- var board = new int[n, m];
- var sums = new List<int>();
- var platforms = new List<int[,]>();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- Console.Write("Index {0},{1}: ", i,j);
- board[i, j] = int.Parse(Console.ReadLine());
- }
- }
- Console.WriteLine(new string('=',30));
- for (int i = 0; i < n && i+2 < n; i++)
- {
- for (int j = 0; j < m && j+2 < m; j++)
- {
- int[,] temp = new int[3,3]
- {
- {board[i,j], board[i,j+1], board[i,j+2]} ,
- {board[i+1,j], board[i+1,j+1], board[i+1,j+2]},
- {board[i+2,j], board[i+2,j+1], board[i+2,j+2]}
- };
- platforms.Add(temp);
- int sum = 0;
- foreach (var value in temp)
- {
- sum += value;
- }
- sums.Add(sum);
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- string temp = string.Join("", board[i, j]);
- Console.Write(temp.PadRight(4,' '));
- }
- Console.WriteLine();
- }
- Console.WriteLine(new string('=',30));
- var maxIndex = sums.IndexOf(sums.Max());
- Console.WriteLine("Platform 3x3 with maximal sum({0}):",sums.Max());
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- string temp = string.Join("", platforms[maxIndex][i, j]);
- Console.Write(temp.PadRight(4,' '));
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment