Advertisement
HTsekin

Untitled

Jan 7th, 2021 (edited)
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.30 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Core_Tasks_2
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //int size = 5;
  11.             int size = Int32.Parse(Console.ReadLine());
  12.  
  13.             string[][] matrix = new string[size][];
  14.  
  15.             //int[][] matrix = new int[][]
  16.             //{
  17.             //    new int[] { 1, 22, 3, 41, 5, 2 },
  18.             //    new int[] { 2, 13, 4, -5, 6, 5 },
  19.             //    new int[] { -6, 5, 9, 31, 2, 8 },
  20.             //    new int[] { 3, 14, 5, -6, 7, 4 },
  21.             //    new int[] { 4, -5, 6, -7, 8, 7 },
  22.             //};
  23.  
  24.             long sum = Int64.MinValue;
  25.  
  26.             for (int row = 0; row < size; row++)
  27.             {
  28.  
  29.                 matrix[row] = Console.ReadLine().Split(' ');
  30.  
  31.             }
  32.  
  33.  
  34.  
  35.             //int[] rc = "-3 -3 3 3 4 -3 -4 3".Split(' ').Select(n => Int32.Parse(n)).ToArray();
  36.             int[] rc = Console.ReadLine().Split(' ').Select(n => Int32.Parse(n)).ToArray();
  37.  
  38.  
  39.             for (int i = 0; i < rc.Length; i += 2)
  40.             {
  41.                 int rowLength = matrix[0].Length;
  42.  
  43.                 int r = rc[i];
  44.                 int c = rc[i + 1];
  45.  
  46.                 Console.WriteLine(r + "  " + c);
  47.  
  48.                 int sPointX = 0;
  49.                 int sPointY = 0;
  50.  
  51.                 int ePointX = 0;
  52.                 int ePointY = 0;
  53.  
  54.  
  55.  
  56.                 if (r < 0)
  57.                 {
  58.                     sPointX = rowLength - 1;
  59.                     sPointY = Math.Abs(r) - 1;
  60.                 }
  61.                 else
  62.                 {
  63.                     sPointX = 0;
  64.                     sPointY = r - 1;
  65.                 }
  66.  
  67.                 if (c < 0)
  68.                 {
  69.                     ePointX = Math.Abs(c) - 1;
  70.                     ePointY = size - 1;
  71.                 }
  72.                 else
  73.                 {
  74.                     ePointX = c - 1;
  75.                     ePointY = 0;
  76.                 }
  77.  
  78.                 //Console.WriteLine("Initial Y: " + sPointY + " X: " + sPointX);
  79.  
  80.                 bool alive = true;
  81.                 bool horizontal = true;
  82.                 bool vertical = false;
  83.  
  84.                 int tmpSum = 0;
  85.                 //Console.WriteLine();
  86.  
  87.                 while (alive)
  88.                 {
  89.  
  90.                     //Console.WriteLine("Sequence: " + matrix[sPointY][sPointX]);
  91.                     //Console.WriteLine("Y: " + sPointY + " X: " +sPointX);
  92.  
  93.  
  94.                     tmpSum += Int32.Parse(matrix[sPointY][sPointX]);
  95.  
  96.                     if (sPointX == ePointX && sPointY == ePointY)
  97.                         break;
  98.  
  99.                     if (r < 0)
  100.                     {
  101.                         if (sPointX == ePointX)
  102.                         {
  103.                             horizontal = false;
  104.                             vertical = true;
  105.                         }
  106.  
  107.                         if (horizontal)
  108.                         {
  109.                             sPointX--;
  110.                         }
  111.  
  112.                     }
  113.                     else
  114.                     {
  115.                         if (sPointX == ePointX)
  116.                         {
  117.                             horizontal = false;
  118.                             vertical = true;
  119.                         }
  120.  
  121.                         if (horizontal)
  122.                         {
  123.                             sPointX++;
  124.                         }
  125.                     }
  126.  
  127.                     if (c < 0)
  128.                     {
  129.                         if (sPointY == ePointY)
  130.                         {
  131.                             vertical = true;
  132.                         }
  133.  
  134.                         if (vertical)
  135.                         {
  136.                             sPointY++;
  137.                         }
  138.  
  139.  
  140.  
  141.                     }
  142.                     else
  143.                     {
  144.                         if (sPointY == ePointY)
  145.                         {
  146.                             vertical = false;
  147.                         }
  148.  
  149.                         if (vertical)
  150.                         {
  151.                             sPointY--;
  152.                         }
  153.                     }
  154.  
  155.  
  156.                 }
  157.  
  158.                 //Console.WriteLine(tmpSum);
  159.  
  160.  
  161.                 if (tmpSum > sum)
  162.                     sum = tmpSum;
  163.             }
  164.  
  165.  
  166.             Console.WriteLine(sum);
  167.         }
  168.     }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement