Advertisement
Valleri

Joro the naughty - C#

Jul 18th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4.  
  5.  
  6. class Program
  7. {
  8.     static void Main(string[] args)
  9.     {
  10.         string buffer = Console.ReadLine();
  11.         string[] container = buffer.Split(' ');
  12.         int n = int.Parse(container[0]);
  13.         int m = int.Parse(container[1]);
  14.         int jumps = int.Parse(container[2]);
  15.  
  16.         buffer = Console.ReadLine();
  17.         container = buffer.Split(' ');
  18.  
  19.         int start_row = int.Parse(container[0]);
  20.         int start_col = int.Parse(container[1]);
  21.  
  22.         //create the matrix
  23.         int[,] matrix = new int[n, m];
  24.         int counter = 1;
  25.         List<int> numbersJumpedOn = new List<int>();
  26.  
  27.         for (int i = 0; i < n; i++)
  28.         {
  29.             for (int j = 0; j < m; j++)
  30.             {
  31.                 matrix[i, j] = counter++;
  32.             }
  33.         }
  34.  
  35.         //adding starting position to the arraylIst
  36.         numbersJumpedOn.Add(matrix[start_row, start_col]);
  37.  
  38.         List<string> allJumps = new List<string>();
  39.  
  40.         for (int i = 0; i < jumps; i++)
  41.         {
  42.             allJumps.Add(Console.ReadLine());
  43.         }
  44.         int k = 0;
  45.         while(true)
  46.         {
  47.             if (k > jumps-1)
  48.             {
  49.                 k = 0;
  50.             }
  51.             container = allJumps[k].Split(' ');
  52.             k++;
  53.  
  54.             int nextJum_row = int.Parse(container[0]);
  55.             int nextJum_col = int.Parse(container[1]);
  56.  
  57.             start_row += nextJum_row;
  58.             start_col += nextJum_col;
  59.  
  60.             if (start_row < 0 || start_col < 0 || start_row > n-1 || start_col > m-1)
  61.             {
  62.                 Console.WriteLine("escaped {0}", Sum(numbersJumpedOn));
  63.                 break;
  64.             }
  65.             if (numbersJumpedOn.IndexOf(matrix[start_row, start_col]) == -1)
  66.             {
  67.                 numbersJumpedOn.Add(matrix[start_row, start_col]);
  68.             }
  69.             else
  70.             {
  71.                 Console.WriteLine("caught {0}", numbersJumpedOn.Count-1);
  72.                 break;
  73.             }
  74.         }
  75.     }
  76.  
  77.     public static int Sum(List<int> baba)
  78.     {
  79.         int sum = 0;
  80.         foreach (var item in baba)
  81.         {
  82.             sum += item;
  83.         }
  84.         return sum;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement