Advertisement
iliya87

04.SpiralMatrix

Mar 24th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 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.  
  8. class Program
  9. {
  10.     static void Main(string[] args)
  11.     {
  12.         int n = int.Parse(Console.ReadLine());
  13.         string word = Console.ReadLine().ToUpper();
  14.            
  15.         char[,] charMatrix = new char[n,n];
  16.  
  17.         int x = 0, y = 0, size = n, currentChar=0;
  18.  
  19.         while (size > 0)
  20.         {
  21.             for (int i = y; i <= y + size - 1; i++)
  22.             {
  23.                 charMatrix[x, i] = word[currentChar % word.Length];
  24.                 currentChar++;
  25.             }
  26.  
  27.             for (int j = x + 1; j <= x + size - 1; j++)
  28.             {
  29.                 charMatrix[j, y + size - 1] = word[currentChar % word.Length];
  30.                 currentChar++;
  31.             }
  32.  
  33.             for (int i = y + size - 2; i >= y; i--)
  34.             {
  35.                 charMatrix[x + size - 1, i] = word[currentChar % word.Length];
  36.                 currentChar++;
  37.             }
  38.  
  39.             for (int i = x + size - 2; i >= x + 1; i--)
  40.             {
  41.                 charMatrix[i, y] = word[currentChar % word.Length];
  42.                 currentChar++;
  43.             }
  44.  
  45.             x = x + 1;
  46.             y = y + 1;
  47.             size = size - 2;
  48.         }
  49.         int maxWeight = 0, rowNumber=0;
  50.         for (int i = 0; i < charMatrix.GetLength(0); i++)
  51.         {
  52.             int currentWeight = 0;
  53.             for (int j = 0; j < charMatrix.GetLength(1); j++)
  54.             {
  55.                 currentWeight += (charMatrix[i, j] - 64);
  56.             }
  57.             if ( currentWeight > maxWeight)
  58.             {
  59.                 maxWeight = currentWeight ;
  60.                 rowNumber = i;
  61.             }
  62.            
  63.         }
  64.         Console.WriteLine(rowNumber + " - " + maxWeight * 10);
  65.        
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement