Advertisement
reking12

Untitled

Jun 17th, 2019
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.90 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P01The_Garden
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             char[][] matrix = new char[n][];
  12.             int harmed = 0;
  13.             int carrots = 0;
  14.             int potatoes = 0;
  15.             int l = 0;
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 char[] input = Console.ReadLine().Split().Select(char.Parse).ToArray();
  20.                 matrix[i] = input;
  21.             }
  22.             while (true)
  23.             {
  24.                 string end = Console.ReadLine();
  25.                 if (end == "End of Harvest")
  26.                 {
  27.                     break;
  28.                 }
  29.                 string[] input = end.Split();
  30.                 int row = int.Parse(input[1]);
  31.                 int col = int.Parse(input[2]);
  32.  
  33.                 if (input[0] == "Harvest")
  34.                 {
  35.                     if (IsInside(row, col, n, matrix) == true)
  36.                     {
  37.                         if (matrix[row][col] == 'L' || matrix[row][col] == 'P' || matrix[row][col] == 'C')
  38.                         {
  39.                             if (matrix[row][col] == 'C')
  40.                             {
  41.                                 carrots++;
  42.                             }
  43.                             if (matrix[row][col] == 'P')
  44.                             {
  45.                                 potatoes++;
  46.                             }
  47.                             if (matrix[row][col] == 'L')
  48.                             {
  49.                                 l++;
  50.                             }
  51.                             matrix[row][col] = ' ';
  52.                         }
  53.                     }
  54.                 }
  55.                 else if (input[0] == "Mole")
  56.                 {
  57.  
  58.                     if (matrix[row][col] == 'L' || matrix[row][col] == 'P' || matrix[row][col] == 'C')
  59.                     {
  60.                         matrix[row][col] = ' ';
  61.                         harmed++;
  62.                     }
  63.                     while (true)
  64.                     {
  65.                         if (input[3] == "up")
  66.                         {
  67.                             if (datiebamaikata(row - 2, col, n, matrix, harmed) == false)
  68.                             {
  69.                                 break;
  70.                             }
  71.                             if (mnsumprost(row - 2, col, matrix))
  72.                             {
  73.                                 harmed++;
  74.                             }
  75.                             Mole(row - 2, col, n, matrix, harmed);
  76.                             row -= 2;
  77.                            
  78.                         }
  79.                         if (input[3] == "down")
  80.                         {
  81.                             if (datiebamaikata(row + 2, col, n, matrix, harmed) == false)
  82.                             {
  83.                                 break;
  84.                             }
  85.                             if (mnsumprost(row + 2, col, matrix))
  86.                             {
  87.                                 harmed++;
  88.                             }
  89.                             Mole(row + 2, col, n, matrix, harmed);
  90.                             row += 2;
  91.                         }
  92.                         if (input[3] == "left")
  93.                         {
  94.                             if (datiebamaikata(row, col - 2, n, matrix, harmed) == false)
  95.                             {
  96.                                 break;
  97.                             }
  98.                             if (mnsumprost(row, col - 2, matrix))
  99.                             {
  100.                                 harmed++;
  101.                             }
  102.                             Mole(row, col - 2, n, matrix, harmed);
  103.                             col -= 2;
  104.                         }
  105.                         if (input[3] == "right")
  106.                         {
  107.                             if (datiebamaikata(row, col + 2, n, matrix, harmed) == false)
  108.                             {
  109.                                 break;
  110.                             }
  111.                             if (mnsumprost(row, col + 2,matrix))
  112.                             {
  113.                                 harmed++;
  114.                             }
  115.                             Mole(row, col + 2, n, matrix, harmed);
  116.                             col += 2;
  117.                         }
  118.                     }
  119.                 }
  120.             }
  121.             foreach (var item in matrix)
  122.             {
  123.                 Console.WriteLine(string.Join(" ", item));
  124.             }
  125.             Console.WriteLine($"Carrots: {carrots}");
  126.             Console.WriteLine($"Potatoes: {potatoes}");
  127.             Console.WriteLine($"Lettuce: {l}");
  128.             Console.WriteLine($"Harmed vegetables: {harmed}");
  129.            
  130.         }
  131.         public static void Mole(int row, int col, int n, char[][] matrix,int harmed)
  132.         {
  133.             if(IsInside(row, col, n, matrix))
  134.             {
  135.                 if (matrix[row][col] == 'L' || matrix[row][col] == 'P' || matrix[row][col] == 'C')
  136.                 {
  137.                     matrix[row][col] = ' ';
  138.                 }
  139.             }
  140.         }
  141.         public static bool datiebamaikata(int row, int col, int n, char[][] matrix, int harmed)
  142.         {
  143.             if (IsInside(row, col, n, matrix))
  144.             {
  145.                 return true;
  146.             }
  147.             return false;
  148.         }
  149.         public static bool IsInside(int row, int col, int n, char[][] matrix)
  150.         {
  151.             if (row < 0 || row >= n || col < 0 || col >= matrix[row].Length)
  152.             {
  153.                 return false;
  154.             }
  155.             return true;
  156.         }
  157.         public static bool mnsumprost(int row, int col, char[][] matrix)
  158.         {
  159.             if (matrix[row][col] == ' ')
  160.             {
  161.                 return false;
  162.             }
  163.             return true;
  164.         }
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement