archangelmihail

Trapezoid

Dec 3rd, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 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 Trapezoid
  8. {
  9.     class Trapezoid
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //input
  14.             int number = int.Parse(Console.ReadLine());
  15.             int[,] matrix = new int [number+1, 2*number];
  16.  
  17.             // solution
  18.             int currentRow = 0;
  19.             int currentCol = 0;
  20.             while (true)
  21.             {
  22.                 if (currentRow == 0 && currentCol == 2* number -1)
  23.                 {
  24.                     matrix[currentRow, currentCol] = 1;
  25.                     currentRow++;
  26.                     currentCol = number - 1;
  27.                 }
  28.                 else if (currentRow== 0 && currentCol < number)
  29.                 {
  30.                     currentCol++;
  31.                 }
  32.                 else if (currentRow == 0 && currentCol >= number && currentCol < 2*number -1)
  33.                 {
  34.                     matrix[currentRow, currentCol] = 1;
  35.                     currentCol++;
  36.                 }
  37.                 else if (currentRow > 0 && currentCol == number - currentRow && currentRow < number)
  38.                 {
  39.                     matrix[currentRow, currentCol] = 1;
  40.                     currentCol++;
  41.                 }
  42.                 else if (currentRow > 0 && currentRow < number && currentCol > number - currentRow && currentCol < 2 * number - 1)
  43.                 {
  44.                     currentCol++;
  45.                 }
  46.                 else if (currentRow > 0 && currentRow < number && currentCol == 2 * number - 1)
  47.                 {
  48.                     matrix[currentRow, currentCol] = 1;
  49.                     currentRow++;
  50.                     currentCol = number - currentRow;
  51.                 }
  52.                 else if (currentRow == number && currentCol < 2* number -1 )
  53.                 {
  54.                     matrix[currentRow, currentCol] = 1;
  55.                     currentCol++;
  56.                 }
  57.                 else if (currentRow == number && currentCol == 2*number -1)
  58.                 {
  59.                     matrix[currentRow, currentCol] = 1;
  60.                     break;
  61.                 }
  62.                
  63.             }
  64.  
  65.             //output
  66.             for (int row = 0; row < (number + 1); row++)
  67.             {
  68.                 for (int col = 0; col < 2*number; col++)
  69.                 {
  70.                    
  71.                     if (matrix[row,col] == 0)
  72.                     {
  73.                         Console.Write('.');                        
  74.                     }
  75.                     if (matrix[row,col] == 1)
  76.                     {
  77.                         Console.Write('*');
  78.                     }
  79.  
  80.                     //Console.Write(matrix[row,col]);
  81.                 }
  82.                 Console.WriteLine();
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment