Advertisement
Gesh4o

CollectResources

Feb 29th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. namespace _04.Events
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class EventsMain
  8. {
  9. public static void Main(string[] args)
  10. {
  11. string[] inputResources = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  12.  
  13. int pathsCount = int.Parse(Console.ReadLine());
  14.  
  15. List<int[]> paths = new List<int[]>();
  16.  
  17. for (int count = 0; count < pathsCount; count++)
  18. {
  19. int[] path =
  20. Console.ReadLine()
  21. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  22. .Select(int.Parse)
  23. .ToArray();
  24. paths.Add(path);
  25. }
  26.  
  27. List<int> totalResources = new List<int>();
  28. for (int i = 0; i < pathsCount; i++)
  29. {
  30. List<int> collectedIndexes = new List<int>();
  31. int currentIndex = paths[i][0];
  32. int currentStep = paths[i][1] % inputResources.Length;
  33. int totalResource = 0;
  34. while (!collectedIndexes.Contains(currentIndex))
  35. {
  36. string[] parsedResource = inputResources[currentIndex].Split('_');
  37. string resourceName = parsedResource[0];
  38. int resourceCount = 1;
  39. if (parsedResource.Length == 2)
  40. {
  41. resourceCount = int.Parse(parsedResource[1]);
  42. }
  43.  
  44. bool isResourceValid = CheckIsResourceValid(resourceName);
  45.  
  46. if (isResourceValid)
  47. {
  48. totalResource += resourceCount;
  49. }
  50.  
  51. collectedIndexes.Add(currentIndex);
  52. currentIndex = (currentIndex + currentStep) % inputResources.Length;
  53. }
  54.  
  55. totalResources.Add(totalResource);
  56. }
  57.  
  58. Console.WriteLine(totalResources.Max());
  59. }
  60.  
  61. private static bool CheckIsResourceValid(string resourceName)
  62. {
  63. bool isResourceValid = resourceName == "stone" || resourceName == "gold" || resourceName == "wood"
  64. || resourceName == "food";
  65. return isResourceValid;
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement