Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Your task is to help the global programmer community. You will receive a set on letter-numbers (strings) on one line separated with a single space ‘ ‘. Sum all of the letter-numbers and print out the resulting sum both in the 23-based system and decimal system. The digits go as following: a -> 0, b -> 1, c -> 2, d -> 3 ... j -> 9, k -> 10 ... v -> 21, w -> 22.
- * Print out the sum of the given numbers in the format “[sum in 23-base numeral system] = [sum in decimal system]”. */
- namespace Calculation_Problem
- {
- using System;
- using System.Linq;
- using System.Text;
- class CalculationProblem
- {
- static void Main(string[] args)
- {
- string[] words = Console.ReadLine().Split();
- int totalSum = words
- .Sum(word => word
- .Select((t, i) => (int)((t - 97) * Math.Pow(23, word.Length - i - 1)))
- .Sum());
- StringBuilder sb = new StringBuilder();
- int quotient = 0;
- int temp = totalSum;
- do
- {
- quotient = temp / 23;
- int remaider = temp % 23;
- sb.Append((char)(remaider + 97));
- temp = quotient;
- } while (quotient != 0);
- string sumIn23NumSystem = sb.ToString();
- char[] letters = sumIn23NumSystem.ToCharArray();
- Array.Reverse(letters);
- Console.WriteLine("{0} = {1}", new String(letters), totalSum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement