archangelmihail

ForestRoadWithMatrix

Dec 1st, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ForestRoadWithMatrix
  8. {
  9.     class ForestRoadWithMatrix
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //input
  14.             int number = int.Parse(Console.ReadLine());
  15.             int[,] matrix = new int [number*2 - 1, number];
  16.  
  17.             // solution
  18.             int currentRow = 0;
  19.             int currentCol = 0;
  20.             bool stop = false;
  21.  
  22.             while (true)
  23.             {
  24.                 matrix[currentRow , currentCol] = 1;
  25.                
  26.                 if (currentCol < number-1 && !stop)
  27.                 {
  28.                     currentRow++ ;
  29.                     currentCol++;
  30.                 }
  31.                 else if(currentCol == number-1 && !stop)
  32.                 {
  33.                      stop = true;
  34.                      currentCol--;
  35.                      currentRow++;
  36.                 }
  37.                 else if (currentCol <number-1 && currentCol >0 && stop )
  38.                 {
  39.                     currentCol--;
  40.                     currentRow++;
  41.                 }
  42.                 else
  43.                 {
  44.                     break;
  45.                 }
  46.             }
  47.  
  48.             //output
  49.             for (int row = 0; row < (2*number -1); row++)
  50.             {
  51.                 for (int col = 0; col < number; col++)
  52.                 {
  53.                    
  54.                     if (matrix[row,col] == 0)
  55.                     {
  56.                         Console.Write('.');                        
  57.                     }
  58.                     if (matrix[row,col] == 1)
  59.                     {
  60.                         Console.Write('*');
  61.                     }
  62.  
  63.                     //Console.Write(matrix[row,col]);
  64.                 }
  65.                 Console.WriteLine();
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment