Advertisement
ivan_yosifov

Kaspichan_Numbers

Dec 10th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2.  
  3. class KaspichanNumbers
  4. {
  5.     const int Base = 256;
  6.     static char[] startingLetter = { '\0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' };
  7.  
  8.     static string ConvertToKaspichan(ulong remainder)
  9.     {
  10.         string kaspichanNum = null;
  11.         ulong rem = remainder % 26;
  12.         ulong div = remainder / 26;
  13.         char first = (char)(rem + 65);
  14.         kaspichanNum += first.ToString();
  15.         if (div != 0)
  16.         {
  17.             for (int i = 1; i < startingLetter.Length; i++)
  18.             {
  19.                 if (div == (ulong)i)
  20.                 {
  21.                     kaspichanNum += startingLetter[i].ToString();
  22.                     break;
  23.                 }
  24.             }
  25.         }
  26.         return kaspichanNum;
  27.     }
  28.     static void Main()
  29.     {
  30.         ulong number = ulong.Parse(Console.ReadLine());
  31.         string kaspichan = null;
  32.        
  33.         while (true)
  34.         {
  35.             ulong remainder = number % Base;
  36.             ulong division = number / Base;
  37.  
  38.             // convert remainder to kaspichan
  39.             kaspichan += ConvertToKaspichan(remainder);
  40.  
  41.             if (division == 0)
  42.             {
  43.                 break;
  44.             }
  45.             if (division < Base)
  46.             {
  47.                 kaspichan += ConvertToKaspichan(division);
  48.                 break;
  49.             }
  50.             else
  51.             {
  52.                 number /= Base;
  53.             }
  54.         }
  55.         for (int i = kaspichan.Length - 1; i >= 0; i--)
  56.         {
  57.             Console.Write("{0}", kaspichan[i]);
  58.         }
  59.         Console.WriteLine();
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement