Advertisement
Opteronic

cs loop j interm Hops - list.Contains(var)

Mar 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. public class Hops
  4. {
  5.     public static void Main()
  6.     {
  7.         string[] raw = "2, -4, -6, 10, 2, 1, 5".Replace(",", "").Split(' '); // Console.ReadLine().Replace(",", "").Split(' '); //
  8.         int len = raw.Length; string dirCell = "";
  9.         int m = 3; //int.Parse(Console.ReadLine()); //
  10.         int a = 0, direction = 0, nextDirCell = 0, sum = 0, st = 0, biggestSum = int.MinValue;
  11.         List<int> listEatenCell = new List<int>();
  12.         for (int row = 0; row < m; row++)
  13.         {
  14.             string[] r = "2, 2, -4".Replace(",", "").Split(' ');//Console.ReadLine().Replace(",", "").Split(' '); //
  15.             a = r.Length;
  16.             int col = 0;
  17.             do
  18.             {
  19.                 st = Convert.ToInt32(raw[nextDirCell]);
  20.                 listEatenCell.Add(nextDirCell);
  21.                 sum = sum + st;
  22.                 if (col >= a)
  23.                     col = 0;
  24.                 dirCell = r[col];
  25.                 direction = Convert.ToInt32(dirCell);//3
  26.                 nextDirCell = nextDirCell + direction;
  27.                 if (listEatenCell.Contains(nextDirCell)) break;
  28.                 col++;
  29.             } while (nextDirCell >= 0 && nextDirCell < len);
  30.             listEatenCell.Clear();
  31.             if (biggestSum < sum) biggestSum = sum;
  32.             nextDirCell = 0; sum = 0;
  33.         }
  34.         Console.WriteLine(biggestSum);
  35.         Console.ReadKey();
  36.     }
  37. }
  38.  
  39.  
  40. /*
  41.  You recently got yourself a new pet - a bunny named Telerik. He is a fluffy cutie that is always
  42.  hungry. So, in order to combat his constant craving, you let him out in your garden to eat
  43.   carrots. Your garden is a narrow path of planted carrot rows, each row can have one or more
  44.  carrots. These carrots can be either good (represented by a positive integer) or bad
  45.   (represented by a negative integer). An example of a field with carrots would be:
  46.   1 3 -6 7 4 1 12 If Telerik eats good carrots, that's fine, but if he eats bad ones
  47.   , his tummy starts hurting and he throws those up. So in the end, the bunny could either
  48.  have eaten some carrots (positive output), or he is even more hungry (negative output).
  49. Telerik is a smart bunny. He can follow directions. The directions you give him are a sequence of
  50.   integers, each of which tells him how many hops to make. If the integer is positive, he hops
  51.   to the right, if the integers are negative, he hops to the left. An example of a sequence of
  52.   directions is 3 2 -1.
  53. He can also process several sequences of directions. Another example of such sequence is 2 -4 2.
  54.   As you can see in this example, the bunny stops hopping only after reaching a row he has already
  55.   visited or if he gets out of the path with carrots. So the given directions can be repeated
  56.   several times.
  57.  nput
  58. The input will be an array of strings
  59. The first element will be the field with carrots - numbers separated with “, ” (comma and space).
  60. The second element will be M – the number of directions to try.
  61. The next M elements of the array will be numbers, separated with “, “(comma and space), representing the directions themselves.
  62. Output
  63. The output should contain the maximal number of carrots, that the bunny can collect and eat using one of the directions sets.
  64. Constraints
  65. The numbers in the field will be in the range [1..10000] inclusive.
  66. Each of the numbers in the field or in the directions will be in the range [-1000..+1000] inclusive.
  67. M will be between in the range [1..500] inclusive.
  68. Each set of directions will contain at most 100 numbers.
  69. Sample tests
  70. Input
  71. Copy
  72. 2, -4, -6, 10, 2, 1, 5
  73. 3
  74. 3, 2, -1
  75. 2, 2, -4
  76. 2, -3
  77. Output
  78. Copy
  79. 15
  80. http://judge.telerikacademy.com/problem/04hops
  81. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement