Advertisement
coasterka

#ExamAnacci

Apr 9th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. // 70/100
  3. class Anacci
  4. {
  5.     static void Main()
  6.     {
  7.         char firstLetterChar = char.Parse(Console.ReadLine());
  8.         char secondLetterChar = char.Parse(Console.ReadLine());
  9.         int lines = int.Parse(Console.ReadLine());
  10.         char whiteSpace = ' ';
  11.  
  12.         int firstLetterCode = ParseCharToInt(firstLetterChar);
  13.         int secondLetterCode = ParseCharToInt(secondLetterChar);
  14.  
  15.         int nextLetterCode = ParseCharToInt(firstLetterChar);
  16.        
  17.         for (int i = 0; i < lines * 2 - 1; i++)
  18.         {
  19.             nextLetterCode = firstLetterCode;
  20.             firstLetterCode = secondLetterCode;
  21.             secondLetterCode = nextLetterCode + secondLetterCode;
  22.  
  23.             if (nextLetterCode <= 26)
  24.             {
  25.                 if (i % 2 == 0 && i>1)
  26.                 {
  27.                     Console.Write(new string(whiteSpace, i / 2 - 1));
  28.                 }
  29.                 else
  30.                 {
  31.                     Console.WriteLine();
  32.                 }
  33.                 Console.Write(ParseIntToChar(nextLetterCode));
  34.             }
  35.             else if (nextLetterCode > 26)
  36.             {
  37.                 nextLetterCode %= 26;
  38.                 if (i % 2 == 0 && i > 1)
  39.                 {
  40.                     Console.Write(new string(whiteSpace, i / 2 - 1));
  41.                 }
  42.                 else
  43.                 {
  44.                     Console.WriteLine();
  45.                 }
  46.                 Console.Write(ParseIntToChar(nextLetterCode));
  47.             }
  48.         }
  49.     }
  50.  
  51.     private static char ParseIntToChar(int letterCode)
  52.     {
  53.         char c = (char)(letterCode + 64);
  54.         return c;
  55.     }
  56.  
  57.     private static int ParseCharToInt(char c)
  58.     {
  59.         int letterCode = c - 64;
  60.         return letterCode;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement