Advertisement
stanevplamen

02.09.01.01.KaspichanNumber

Jun 19th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class KaspichanNumber
  5. {
  6.     static void Main()
  7.     {
  8.         ulong input = ulong.Parse(Console.ReadLine());
  9.         ulong numSystem = 256;
  10.         List<ulong> listNumbers = ConvertToAny(input, numSystem);
  11.         List<char> charNumbers = ConvertToChar(listNumbers);
  12.         foreach (var ch in charNumbers)
  13.         {
  14.             Console.Write(ch);
  15.         }
  16.     }
  17.  
  18.     private static List<ulong> ConvertToAny(ulong number, ulong numSystem)
  19.     {
  20.         List<ulong> listNumbers = new List<ulong>();
  21.         if (number == 0)
  22.         {
  23.             listNumbers.Add(0);
  24.         }
  25.  
  26.         while (number > 0)
  27.         {
  28.             listNumbers.Add(number % numSystem);
  29.             number = number / numSystem;
  30.         }
  31.  
  32.         listNumbers.Reverse();
  33.  
  34.         return listNumbers;
  35.     }
  36.  
  37.     private static List<char> ConvertToChar(List<ulong> listNumbers)
  38.     {
  39.         List<char> listChars = new List<char>();
  40.         foreach (ulong numb in listNumbers)
  41.         {
  42.             List<ulong> listNumbers26 = new List<ulong>();
  43.             ulong temp = numb;
  44.             if (temp == 0)
  45.             {
  46.                 listNumbers26.Add(0);
  47.             }
  48.  
  49.             while (temp > 0)
  50.             {
  51.                 listNumbers26.Add(temp % 26);
  52.                 temp = temp / 26;
  53.             }
  54.             //listNumbers26.Reverse();
  55.             for (int i = listNumbers26.Count - 1; i >= 0; i--)
  56.             {
  57.                 if (i == 1)
  58.                 {
  59.                     listChars.Add((char)(listNumbers26[i] + 96));
  60.                 }
  61.                 else
  62.                 {
  63.                     listChars.Add((char)(listNumbers26[i] + 65));
  64.                 }
  65.             }
  66.  
  67.         }
  68.         return listChars;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement