Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You are given an array of strings. The jumper can be anywhere in the array and is denoted by the 'o' symbol.
- * You need to determine the movement of the jumper in iterations. On each iteration the jumper moves
- * one line down, pulled by gravity. Additionally, the jumper moves sideways by the wind on the current line.
- * The '>' symbol means the wind is moving the jumper one position to the right.
- * The '<' symbol means the wind is moving the jumper one position to the left.
- * The total direction of the wind on a single line may stack (e.g. '>>>' moves the jumper 3 positions to
- * the right; '><<' moves the jumper 1 position to the left).
- * The jumper will never fly off the map!
- * The jumper can move only through 'air' (the '-' symbol). When the jumper hits the ground, water or a cliff,
- * the jump is finished!
- * Your task is to determine how the jumper will finish his jump and where he will land exactly, based on
- * the gravity and wind parameters!
- * The symbols in input strings will not separated by anything!
- * The output should consist of two lines. On the first line you must display 1 of 3 possible messages:
- * If you have landed on the ground ('_' symbol), the message is: "Landed on the ground like a boss!";
- *If you have landed in the water ('~' symbol), the message is: "Drowned in the water like a cat!";
- *If you have landed on a cliff ('/', '\' or '|' symbol), the message is: "Got smacked on the rock like a dog!".
- *The second line holds the position (the row and col, space-separated) of your landing. */
- namespace Parachute
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Parachute
- {
- static void Main(string[] args)
- {
- List<string> matrix = new List<string>();
- int rowCounter = 0;
- int startRow = 0;
- int startCol = 0;
- string inputLine = Console.ReadLine();
- while (inputLine != "END")
- {
- if (inputLine.Contains('o'))
- {
- startRow = rowCounter;
- startCol = inputLine.IndexOf('o');
- }
- matrix.Add(inputLine);
- rowCounter++;
- inputLine = Console.ReadLine();
- }
- int col = startCol;
- for (int row = startRow + 1; row < matrix.Count; row++)
- {
- col += GetTotalDirectionOfTheWindOnLine(matrix, row);
- switch (matrix[row][col])
- {
- case '/':
- case '\\':
- case '|':
- Console.WriteLine("Got smacked on the rock like a dog!");
- Console.WriteLine("{0} {1}", row, col);
- return;
- case '~':
- Console.WriteLine("Drowned in the water like a cat!");
- Console.WriteLine("{0} {1}", row, col);
- return;
- case '_':
- Console.WriteLine("Landed on the ground like a boss!");
- Console.WriteLine("{0} {1}", row, col);
- return;
- }
- }
- }
- private static int GetTotalDirectionOfTheWindOnLine(List<string> matrix, int row)
- {
- int leftMoves = 0;
- int rightMoves = 0;
- for (int i = 0; i < matrix[row].Length; i++)
- {
- if (matrix[row][i] == '<')
- {
- leftMoves++;
- }
- else if (matrix[row][i] == '>')
- {
- rightMoves++;
- }
- }
- return (rightMoves - leftMoves);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement