Advertisement
stpetkov

Untitled

Dec 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 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. class CalcProblem23
  8. {
  9. static char system(long b)
  10. {
  11. return ((char)(b + 97));
  12. }
  13.  
  14. static long sumOf(string a)
  15. {
  16. long sum = 0;
  17. for (int i = 0; i < a.Length; i++)
  18. {
  19. if (i + 1 == a.Length)
  20. {
  21. sum += a[i] - 'a' * 1;
  22. }
  23. else
  24. {
  25. sum += (long)(a[i] - 'a') * (long)Math.Pow(23, a.Length - i - 1);
  26. }
  27. }
  28. return sum;
  29. }
  30. static void toChar(long sum) {
  31. int pos = 0;
  32. List<char> b = new List<char>();
  33. while (true)
  34. {
  35. b.Add(system(sum % 23));
  36. sum = sum / 23;
  37. pos++;
  38. if (pos + 1 > 10 || sum < 1)
  39. {
  40. break;
  41. }
  42. }
  43. b.Reverse();
  44.  
  45. foreach (var item in b)
  46. {
  47. Console.Write(item);
  48. }
  49.  
  50.  
  51. }
  52.  
  53. static void Main(string[] args)
  54. {
  55. string[] words = Console.ReadLine().Split(' ');
  56. long sum = 0;
  57. foreach (var item in words)
  58. {
  59. sum+=sumOf(item);
  60. }
  61. toChar(sum);
  62. Console.Write(" = {0}",sum);
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement