Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SpyHard
- {
- class SpyHard
- {
- static void Main()
- {
- int key = int.Parse(Console.ReadLine());
- string inputMsg = Console.ReadLine();
- string inputMsgLower = inputMsg.ToLower();
- int symbolsSum = 0;
- for (int i = 0; i < inputMsg.Length; i++)
- {
- if (Char.IsLetter(inputMsgLower[i]))
- {
- symbolsSum += (int)inputMsgLower[i] - 96;
- }
- else
- {
- symbolsSum += (int)inputMsgLower[i];
- }
- }
- Console.WriteLine(key.ToString() + inputMsg.Length.ToString() +
- DecimalToArbitrarySystem(symbolsSum, key));
- }
- public static string DecimalToArbitrarySystem(long decimalNumber, int radix)
- {
- const int BitsInLong = 64;
- const string Digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- if (radix < 2 || radix > Digits.Length)
- throw new ArgumentException("The radix must be >= 2 and <= " + Digits.Length.ToString());
- if (decimalNumber == 0)
- return "0";
- int index = BitsInLong - 1;
- long currentNumber = Math.Abs(decimalNumber);
- char[] charArray = new char[BitsInLong];
- while (currentNumber != 0)
- {
- int remainder = (int)(currentNumber % radix);
- charArray[index--] = Digits[remainder];
- currentNumber = currentNumber / radix;
- }
- string result = new String(charArray, index + 1, BitsInLong - index - 1);
- if (decimalNumber < 0)
- {
- result = "-" + result;
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment