sylviapsh

Forest Road

Dec 26th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. class ForestRoad
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //Geeko, a non-stop learning trainee at Telerik Software Academy lived deep into the Lulin forests. Every time he went to the Academy he had to take a long trip through the forest. Starting from the top left corner of the forest, the road always goes down and right first and when it reaches the border, it goes down and left.
  8.     //On the only line in the console you are given an integer number N, showing the width of the map. The map’s height is always 2*N - 1.
  9.  
  10.     int roadSize = int.Parse(Console.ReadLine()),
  11.         starPos1 = 1,
  12.         starPos2 = 1;
  13.     for (int row = 1; row <= (2*roadSize - 1); row++)
  14.     {
  15.       for (int column = 1; column <= roadSize; column++)
  16.       {
  17.         if (row == starPos2 && column == starPos1)
  18.         {
  19.           Console.Write("*");
  20.         }
  21.         else
  22.         {
  23.           Console.Write(".");
  24.         }
  25.       }
  26.         Console.WriteLine("");
  27.         if (row >= ((2 * roadSize) / 2))
  28.         {
  29.           starPos1--;
  30.           starPos2++;
  31.         }
  32.         else
  33.         {
  34.           starPos1++;
  35.           starPos2++;
  36.         }
  37.     }
  38.    
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment