Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static string baseConverter(int sum, int key)
- {
- string stringsum = string.Empty;
- while (sum > 0)
- {
- int x = sum % key;
- stringsum = (char)(x >= 0 && x <= 9 ? x + 48 : x + 'A' - 10) + stringsum;
- sum /= key;
- }
- return stringsum;
- }
- static void Main(string[] args)
- {
- int key = int.Parse(Console.ReadLine());
- string message = Console.ReadLine();
- char[] array = message.ToCharArray();
- int counterOfSymbols = array.Length;
- int sum = 0;
- string system = string.Empty;
- for (int i = 0; i < array.Length; i++)
- {
- char number = array[i];
- if (Char.IsLetter(number))
- {
- int index = char.ToUpper(number) - 64;
- sum += index;
- }
- else
- {
- int asciiNumber = (int)number;
- sum += asciiNumber;
- }
- }
- Console.WriteLine("{0}{1}{2}", key, counterOfSymbols, baseConverter(sum, key));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment