Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 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. using System.IO;
  7.  
  8. namespace _42.Parcurgere_în_spirală
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int p;
  15.             p = int.Parse(Console.ReadLine());
  16.             int[,] n= new int[p,p];
  17.             for(int i = 0; i <= n.Length; i++)
  18.             {
  19.                 for(int j = 0; j < n.Length; j++)
  20.                 {
  21.                     n[i,j] = int.Parse(Console.ReadLine());
  22.                 }
  23.             }
  24.             int q = n.Length;
  25.             int c = 0;
  26.             while (q != 0)
  27.             {
  28.                 c++;
  29.                 if((c==n.Length/2+1) && (q == n.Length / 2 + 1))
  30.                 {
  31.                     Console.WriteLine(n[c,q]);
  32.                     continue;
  33.                 }
  34.                 for(int i = c; i < q; i++)
  35.                 {
  36.                     Console.WriteLine(i);
  37.                 }
  38.                 for(int i = c+1; i < q; i++)
  39.                 {
  40.                     Console.WriteLine(n[i,q-1]);
  41.                 }
  42.                 for(int i = q - 2; i >= c; i--)
  43.                 {
  44.                     Console.WriteLine(n[q-1,i]);
  45.                 }
  46.                 for(int i = q - 2; i >= c+1; i--)
  47.                 {
  48.                     Console.WriteLine(n[0,i]);
  49.                 }
  50.                 q--;
  51.             }
  52.  
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement