archangelmihail

Nacci

Dec 3rd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 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 Nacci
  8. {
  9.     class Nacci
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<char, byte> nacci = new Dictionary<char, byte>();
  14.             for (char i = 'A'; i <= 'Z'; i++)
  15.             {
  16.                 nacci.Add(i, (byte)(i - 64));
  17.             }
  18.  
  19.             char[] start = new char[2];
  20.             start[0] = char.Parse(Console.ReadLine());
  21.             start[1] = char.Parse(Console.ReadLine());
  22.             byte number = byte.Parse(Console.ReadLine());
  23.             byte spaces = 0;
  24.             int rows = number;
  25.             if (number >= 2)
  26.             {
  27.                 rows = number * 2 - 1;
  28.             }
  29.             for (int i = 0; i < rows; i++)
  30.             {
  31.                 if (i >= 2)
  32.                 {
  33.                     int next = nacci[start[0]] + nacci[start[1]];
  34.                     if (next > 26)
  35.                     {
  36.                         next = next % 26;
  37.                     }
  38.                     start[0] = start[1];
  39.                     start[1] = nacci.ElementAt(next - 1).Key;
  40.                     Console.Write(start[1]);
  41.                     Console.Write(new string(' ', spaces));
  42.                 }
  43.                 else
  44.                 {
  45.                     Console.Write(start[i]);
  46.                     if (i == 0)
  47.                     {
  48.                         Console.WriteLine();
  49.                     }
  50.                 }
  51.  
  52.                 if (i > 0 && i % 2 == 0)
  53.                 {
  54.                     Console.WriteLine();
  55.                     spaces++;
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment