Guest User

A-nacci

a guest
Apr 7th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2.  
  3. class A_nacci
  4. {
  5.     static void Main()
  6.     {
  7.         char inputFirst = char.Parse(Console.ReadLine());
  8.         char inputSecond = char.Parse(Console.ReadLine());
  9.         int l = int.Parse(Console.ReadLine());
  10.  
  11.         char[] a_Nacci = new char[26];
  12.  
  13.         int counter = 0;
  14.         for (char i = 'A'; i <= 'Z'; i++)
  15.         {
  16.             a_Nacci[counter] = i;
  17.             //Console.WriteLine(a_Nacci[counter]); // to see if the array is filled correctly
  18.             counter++;
  19.         }
  20.  
  21.         long a = 1 + Array.IndexOf(a_Nacci, inputFirst); // the index starts from 0 (Example: in our array index of C = 2, we need it to be C = 3)
  22.         long b = 1 + Array.IndexOf(a_Nacci, inputSecond); // same as the above
  23.         long result = 0;
  24.         string whiteSpace = "";
  25.  
  26.         for (int i = 1; i <= l; i++)
  27.         {
  28.             if (i == 1)
  29.             {
  30.                 Console.Write(a_Nacci[a - 1]);
  31.             }
  32.             else if (i == 2)
  33.             {
  34.                 Console.Write(a_Nacci[b - 1]);
  35.                 result = a + b;
  36.                 a = b;
  37.                 b = result;
  38.                 Console.Write("{0}{1}", whiteSpace, a_Nacci[(result - 1) % 26]); //
  39.             }
  40.             else if (i > 2)
  41.             {
  42.                 whiteSpace = whiteSpace + " ";
  43.                 result = a + b;
  44.                 a = b;
  45.                 b = result;
  46.                 Console.Write(a_Nacci[(result - 1) % 26]);
  47.                 result = a + b;
  48.                 a = b;
  49.                 b = result;
  50.                 Console.Write("{0}{1}", whiteSpace, a_Nacci[(result - 1) % 26]);
  51.             }
  52.             Console.WriteLine();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment