Advertisement
vkv1986

Anacci

Jan 9th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2.  
  3. class Anacci
  4. {
  5.     static void Main()
  6.     {
  7.         string firstLetter = Console.ReadLine();
  8.         int previousCode = firstLetter[0] - 64;
  9.         string secondLetter = Console.ReadLine();
  10.         int currentCode = secondLetter[0] - 64;
  11.         int rows = int.Parse(Console.ReadLine());
  12.         int targetNumber = ((rows - 1) * 2) + 1;
  13.         int spaces = 0;
  14.         string[] matrix = new string[Math.Max(targetNumber,2)];
  15.         matrix[0] = firstLetter;
  16.         matrix[1] = secondLetter;
  17.         for (int count = 2; count < targetNumber; count++)
  18.         {
  19.             int nextCode = (previousCode + currentCode) % 26;
  20.             if (nextCode == 0)
  21.             {
  22.                 nextCode = 26;
  23.             }
  24.             string nextLetter = ((char)(nextCode + 64)).ToString();
  25.             matrix[count] = nextLetter;
  26.             previousCode = currentCode;
  27.             currentCode = nextCode;
  28.         }
  29.         Console.WriteLine(matrix[0]);
  30.         for (int count = 1; count < rows; count++)
  31.         {
  32.             Console.Write("{0}", matrix[((count - 1) * 2) + 1]);
  33.             for (int iteration = 0; iteration < spaces; iteration++)
  34.             {
  35.                 Console.Write(" ");
  36.             }
  37.             Console.Write("{0}", matrix[count * 2]);
  38.             Console.WriteLine();
  39.             spaces++;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement