Advertisement
dimipan80

Parachute

May 25th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.80 KB | None | 0 0
  1. /* You are given an array of strings. The jumper can be anywhere in the array and is denoted by the 'o' symbol.
  2.  * You need to determine the movement of the jumper in iterations. On each iteration the jumper moves
  3.  * one line down, pulled by gravity. Additionally, the jumper moves sideways by the wind on the current line.
  4.  * The '>' symbol means the wind is moving the jumper one position to the right.
  5.  * The '<' symbol means the wind is moving the jumper one position to the left.
  6.  * The total direction of the wind on a single line may stack (e.g. '>>>' moves the jumper 3 positions to
  7.  * the right; '><<' moves the jumper 1 position to the left).
  8.  * The jumper will never fly off the map!
  9.  * The jumper can move only through 'air' (the '-' symbol). When the jumper hits the ground, water or a cliff,
  10.  * the jump is finished!
  11.  * Your task is to determine how the jumper will finish his jump and where he will land exactly, based on
  12.  * the gravity and wind parameters!
  13.  * The symbols in input strings will not separated by anything!
  14.  * The output should consist of two lines. On the first line you must display 1 of 3 possible messages:
  15.  * If you have landed on the ground ('_' symbol), the message is: "Landed on the ground like a boss!";
  16.  *If you have landed in the water ('~' symbol), the message is: "Drowned in the water like a cat!";
  17.  *If you have landed on a cliff ('/', '\' or '|' symbol), the message is: "Got smacked on the rock like a dog!".
  18.  *The second line holds the position (the row and col, space-separated) of your landing. */
  19.  
  20. namespace Parachute
  21. {
  22.     using System;
  23.     using System.Collections.Generic;
  24.     using System.Linq;
  25.  
  26.     class Parachute
  27.     {
  28.         static void Main(string[] args)
  29.         {
  30.             List<string> matrix = new List<string>();
  31.             int rowCounter = 0;
  32.             int startRow = 0;
  33.             int startCol = 0;
  34.             string inputLine = Console.ReadLine();
  35.             while (inputLine != "END")
  36.             {
  37.                 if (inputLine.Contains('o'))
  38.                 {
  39.                     startRow = rowCounter;
  40.                     startCol = inputLine.IndexOf('o');
  41.                 }
  42.  
  43.                 matrix.Add(inputLine);
  44.                 rowCounter++;
  45.                 inputLine = Console.ReadLine();
  46.             }
  47.  
  48.             int col = startCol;
  49.             for (int row = startRow + 1; row < matrix.Count; row++)
  50.             {
  51.                 col += GetTotalDirectionOfTheWindOnLine(matrix, row);
  52.                 switch (matrix[row][col])
  53.                 {
  54.                     case '/':
  55.                     case '\\':
  56.                     case '|':
  57.                         Console.WriteLine("Got smacked on the rock like a dog!");
  58.                         Console.WriteLine("{0} {1}", row, col);
  59.                         return;
  60.                     case '~':
  61.                         Console.WriteLine("Drowned in the water like a cat!");
  62.                         Console.WriteLine("{0} {1}", row, col);
  63.                         return;
  64.                     case '_':
  65.                         Console.WriteLine("Landed on the ground like a boss!");
  66.                         Console.WriteLine("{0} {1}", row, col);
  67.                         return;
  68.                 }
  69.             }
  70.         }
  71.  
  72.         private static int GetTotalDirectionOfTheWindOnLine(List<string> matrix, int row)
  73.         {
  74.             int leftMoves = 0;
  75.             int rightMoves = 0;
  76.             for (int i = 0; i < matrix[row].Length; i++)
  77.             {
  78.                 if (matrix[row][i] == '<')
  79.                 {
  80.                     leftMoves++;
  81.                 }
  82.                 else if (matrix[row][i] == '>')
  83.                 {
  84.                     rightMoves++;
  85.                 }
  86.             }
  87.  
  88.             return (rightMoves - leftMoves);
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement