Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _04.Events
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class EventsMain
- {
- public static void Main(string[] args)
- {
- string[] inputResources = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- int pathsCount = int.Parse(Console.ReadLine());
- List<int[]> paths = new List<int[]>();
- for (int count = 0; count < pathsCount; count++)
- {
- int[] path =
- Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- paths.Add(path);
- }
- List<int> totalResources = new List<int>();
- for (int i = 0; i < pathsCount; i++)
- {
- List<int> collectedIndexes = new List<int>();
- int currentIndex = paths[i][0];
- int currentStep = paths[i][1] % inputResources.Length;
- int totalResource = 0;
- while (!collectedIndexes.Contains(currentIndex))
- {
- string[] parsedResource = inputResources[currentIndex].Split('_');
- string resourceName = parsedResource[0];
- int resourceCount = 1;
- if (parsedResource.Length == 2)
- {
- resourceCount = int.Parse(parsedResource[1]);
- }
- bool isResourceValid = CheckIsResourceValid(resourceName);
- if (isResourceValid)
- {
- totalResource += resourceCount;
- }
- collectedIndexes.Add(currentIndex);
- currentIndex = (currentIndex + currentStep) % inputResources.Length;
- }
- totalResources.Add(totalResource);
- }
- Console.WriteLine(totalResources.Max());
- }
- private static bool CheckIsResourceValid(string resourceName)
- {
- bool isResourceValid = resourceName == "stone" || resourceName == "gold" || resourceName == "wood"
- || resourceName == "food";
- return isResourceValid;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement