Advertisement
minnera

#30daysofcode #day11

Oct 8th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. //https://www.hackerrank.com/challenges/30-2d-arrays/
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7.  
  8. class Solution {
  9.  
  10.     static void Main(String[] args) {
  11.         int[][] arr = new int[6][];
  12.         for(int arr_i = 0; arr_i < 6; arr_i++){
  13.            string[] arr_temp = Console.ReadLine().Split(' ');
  14.            arr[arr_i] = Array.ConvertAll(arr_temp,Int32.Parse);
  15.         }
  16.        
  17.         int[] sums = new int[16];
  18.         //for(int i = 0; i < 16; i++){
  19.         //  sums[i] = 0;
  20.         //}
  21.        
  22.         int helper = 0;
  23.        
  24.         for(int j = 0; j < 4; j++){
  25.           for(int i = 0; i < 4; i++){
  26.             sums[helper] = (arr[j][i] + arr[j][i+1] + arr[j][i+2] + arr[j+1][i+1] + arr[j+2][i] + arr[j+2][i+1] + arr[j+2][i+2]);
  27.             //Console.WriteLine(sums[helper]);
  28.             helper++;
  29.           }
  30.         }
  31.        
  32.         //Console.WriteLine(helper);
  33.         //Console.WriteLine(sums[helper-1]);
  34.        
  35.         int max = sums[0];
  36.         for(int i = 1; i < 16; i++){
  37.           if(sums[i] > max){
  38.             max = sums[i];
  39.           }
  40.         }
  41.        
  42.         Console.WriteLine(max);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement