Advertisement
Guest User

Untitled

a guest
Mar 8th, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 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 _1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] catNumbersDict = new string[23];
  14. for (int i = 0; i < catNumbersDict.Length; i++)
  15. {
  16. catNumbersDict[i] = ((char)(97 + i)).ToString();
  17. }
  18. string[] numbers = Console.ReadLine()
  19. .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  20.  
  21. var numbersIn23th = new List<List<int>>();
  22.  
  23. // get the numbers in 23th system
  24. for (int j = 0; j < numbers.Length; j++)
  25. {
  26. string currentMewNum = numbers[j];
  27. // for every mew number
  28. var numIn23 = new List<int>();
  29. foreach (var digit in currentMewNum)
  30. {
  31. for (int k = 0; k < catNumbersDict.Length; k++)
  32. {
  33. if (digit.ToString() == catNumbersDict[k])
  34. {
  35. numIn23.Add(k);
  36. }
  37. }
  38. }
  39. numbersIn23th.Add(numIn23);
  40. }
  41. // Console.WriteLine(string.Join("!", numbersIn23th));
  42. var numbersInDecimal = new List<int>();
  43. int numberInDecimal = 0;
  44. for (int curNum = 0; curNum < numbersIn23th.Count; curNum++)
  45. {
  46. for (int currDigit = 0; currDigit < numbersIn23th[curNum].Count; currDigit++)
  47. {
  48. int pow = numbersIn23th[curNum].Count - currDigit - 1;
  49. int curentDigit = numbersIn23th[curNum][currDigit];
  50. numberInDecimal += curentDigit * (int)Math.Pow(23, pow);
  51. }
  52. numbersInDecimal.Add(numberInDecimal);
  53. numberInDecimal = 0;
  54. }
  55.  
  56. //sum in decimal
  57. int sumDec = 0;
  58. for (int i = 0; i < numbersInDecimal.Count; i++)
  59. {
  60. sumDec += numbersInDecimal[i];
  61. }
  62. //convert the sum in 23th system
  63. string result = DecimalToAny(23, sumDec);
  64. Console.WriteLine("{0} = {1}", result, sumDec);
  65. }
  66. private static string DecimalToAny(int d, int decimalResult)
  67. {
  68. string result = string.Empty;
  69. if (decimalResult == 0) result = "0";
  70. while (decimalResult > 0)
  71. {
  72.  
  73. int remainder = decimalResult % d;
  74.  
  75. result += (char)((remainder + 97));
  76.  
  77. decimalResult /= d;
  78.  
  79. }
  80. var reverseResult = result.ToCharArray().Reverse();
  81. return string.Join("", reverseResult);
  82. }
  83.  
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement