stefan1919

Spy Hard

Aug 12th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 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 ConsoleApplication2
  8. {
  9.     class Program
  10.     {
  11.         static string baseConverter(int sum, int key)
  12.         {
  13.             string stringsum = string.Empty;
  14.             while (sum > 0)
  15.             {
  16.                 int x = sum % key;
  17.                 stringsum = (char)(x >= 0 && x <= 9 ? x + 48 : x + 'A' - 10) + stringsum;
  18.                 sum /= key;
  19.             }
  20.             return stringsum;
  21.         }
  22.         static void Main(string[] args)
  23.         {
  24.             int key = int.Parse(Console.ReadLine());
  25.             string message = Console.ReadLine();
  26.             char[] array = message.ToCharArray();
  27.             int counterOfSymbols = array.Length;
  28.             int sum = 0;
  29.             string system = string.Empty;
  30.             for (int i = 0; i < array.Length; i++)
  31.             {
  32.                 char number = array[i];
  33.                
  34.                 if (Char.IsLetter(number))
  35.                 {
  36.                     int index = char.ToUpper(number) - 64;
  37.                     sum += index;
  38.                 }
  39.                 else
  40.                 {
  41.                     int asciiNumber = (int)number;
  42.                     sum += asciiNumber;
  43.                 }
  44.             }
  45.            
  46.             Console.WriteLine("{0}{1}{2}", key, counterOfSymbols, baseConverter(sum, key));
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment