01. The Garden - C# Advanced Demo Exam
Здравейте, може ли някой да прати решение на задача 01. The Garden от демо изпита, благодаря предварително!
Здравейте, може ли някой да прати решение на задача 01. The Garden от демо изпита, благодаря предварително!
nadqvam se che shte vidish tova predi izpita utre
zadachata ne e 100/100 za jalost minava samo 87/100, no mislq, che bi ti pomognala!
Zapovqdai i uspeh utre!
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
string[][] array = new string[n][];
for (int i = 1; i <= n; i++)
{
string[] inputData = Console.ReadLine()
.Split(" ", StringSplitOptions.RemoveEmptyEntries);
array[i] = new string[inputData.Length];
for (int j = 0; j < inputData.Length; j++)
{
array[j][i] = inputData[j];
}
}
string[] command = Console.ReadLine()
.Split();
List<string> commands = Console.ReadLine()
.Split()
.ToList();
int harmedCount = 0;
int carrots = 0;
int potatoes = 0;
int lettuce = 0;
while (commands[0] != "End" && command[1] != "of" && command[2] != "Harvest")
{
if (command[0] == "Harvest")
{
int fisrtIndex = int.Parse(command[1]);
int secIndex = int.Parse(command[2]);
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array[i].Length; j++)
{
if (i == fisrtIndex && j == secIndex)
{
if (array[i][j] == "C")
{
carrots++;
}
else if (array[i][j] == "P")
{
potatoes++;
}
else if (array[i][j] == "L")
{
lettuce++;
}
array[i][j] = " ";
}
}
}
}
else if (command[0] == "Mole")
{
int firstIndex = int.Parse(command[1]);
int secIndex = int.Parse(command[2]);
string side = command[3];
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array[i].Length; j++)
{
if (i == firstIndex && j == secIndex && array[i][j] != " ")
{
if (side == "up")
{
for (int k = firstIndex; k >= 0; k -= 2)
{
if (array[k][secIndex] != " ")
{
array[k][secIndex] = " ";
harmedCount++;
}
}
}
else if (side == "down")
{
for (int k = firstIndex; k < array.Length; k += 2)
{
if (array[k][secIndex] != " ")
{
array[k][secIndex] = " ";
harmedCount++;
}
}
}
else if (side == "right")
{
for (int k = secIndex; k < array[i].Length; k += 2)
{
if (array[firstIndex][k] != " ")
{
array[firstIndex][k] = " ";
harmedCount++;
}
}
}
else if (side == "left")
{
for (int k = secIndex; k >= 0; k -= 2)
{
if (array[firstIndex][k] != " ")
{
array[firstIndex][k] = " ";
harmedCount++;
}
}
}
}
}
}
}
command = Console.ReadLine()
.Split();
}
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array[i].Length; j++)
{
Console.Write(array[i][j] + " ");
}
Console.WriteLine();
}
Console.WriteLine($"Carrots: {carrots}");
Console.WriteLine($"Potatoes: {potatoes}");
Console.WriteLine($"Lettuce: {lettuce}");
Console.WriteLine($"Harmed vegetables: {harmedCount}");
}
}
zdravei otnovo :D
sujalqvam izpratila sum napulno greshen kod....
TOVA TUK E VERNIQ ----->
using System;
using System.Collections.Generic;
namespace The_Garden
{
public class Program
{
public static void Main(string[] args)
{
int rowsCount = int.Parse(Console.ReadLine());
string[][] array = new string[rowsCount][];
for (int i = 0; i < rowsCount; i++)
{
string[] inputData = Console.ReadLine()
.Split(" ", StringSplitOptions.RemoveEmptyEntries);
array[i] = new string[inputData.Length];
for (int j = 0; j < inputData.Length; j++)
{
array[i][j] = inputData[j];
}
}
string[] command = Console.ReadLine()
.Split();
int harmedCount = 0;
int carrots = 0;
int potatoes = 0;
int lettuce = 0;
while (command[0] != "End" && command[1] != "of" && command[2] != "Harvest")
{
if (command[0] == "Harvest")
{
int firstIndex = int.Parse(command[1]);
int secIndex = int.Parse(command[2]);
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array[i].Length; j++)
{
if (i == firstIndex && j == secIndex)
{
if (array[i][j] == "C")
{
carrots++;
}
else if (array[i][j] == "P")
{
potatoes++;
}
else if (array[i][j] == "L")
{
lettuce++;
}
array[i][j] = " ";
}
}
}
}
else if (command[0] == "Mole")
{
int firstIndex = int.Parse(command[1]);
int secIndex = int.Parse(command[2]);
string side = command[3];
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array[i].Length; j++)
{
if (i == firstIndex && j == secIndex && array[i][j] != " ")
{
if (side == "up")
{
for (int k = firstIndex; k >= 0; k -= 2)
{
if (array[k][secIndex] != " ")
{
array[k][secIndex] = " ";
harmedCount++;
}
}
}
else if (side == "down")
{
for (int k = firstIndex; k < array.Length; k += 2)
{
if (array[k][secIndex] != " ")
{
array[k][secIndex] = " ";
harmedCount++;
}
}
}
else if (side == "right")
{
for (int k = secIndex; k < array[i].Length; k += 2)
{
if (array[firstIndex][k] != " ")
{
array[firstIndex][k] = " ";
harmedCount++;
}
}
}
else if (side == "left")
{
for (int k = secIndex; k >= 0; k -= 2)
{
if (array[firstIndex][k] != " ")
{
array[firstIndex][k] = " ";
harmedCount++;
}
}
}
}
}
}
}
command = Console.ReadLine()
.Split();
}
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < array[i].Length; j++)
{
Console.Write(array[i][j] + " ");
}
Console.WriteLine();
}
Console.WriteLine($"Carrots: {carrots}");
Console.WriteLine($"Potatoes: {potatoes}");
Console.WriteLine($"Lettuce: {lettuce}");
Console.WriteLine($"Harmed vegetables: {harmedCount}");
}
}
}