Advertisement
Gesh4o

SoftUniNumerals

Feb 29th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. namespace _03.SoftUniNumerals
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Numerics;
  7.  
  8. public class SoftUniNumerals
  9. {
  10. public static void Main(string[] args)
  11. {
  12. string input = Console.ReadLine();
  13.  
  14. string zero = "aa";
  15. string one = "aba";
  16. string two = "bcc";
  17. string three = "cc";
  18. string four = "cdc";
  19.  
  20. int totalDigits = 0;
  21. List<int> digits = new List<int>();
  22.  
  23. while (input.Length > 0)
  24. {
  25. if (input.StartsWith(zero))
  26. {
  27. input = input.Substring(zero.Length, input.Length - zero.Length);
  28. digits.Add(0);
  29. totalDigits++;
  30. }
  31. else if (input.StartsWith(one))
  32. {
  33. input = input.Substring(one.Length, input.Length - one.Length);
  34. digits.Add(1);
  35. totalDigits++;
  36. }
  37. else if (input.StartsWith(two))
  38. {
  39. input = input.Substring(two.Length, input.Length - two.Length);
  40. digits.Add(2);
  41. totalDigits++;
  42. }
  43. else if (input.StartsWith(three))
  44. {
  45. input = input.Substring(three.Length, input.Length - three.Length);
  46. digits.Add(3);
  47. totalDigits++;
  48. }
  49. else if (input.StartsWith(four))
  50. {
  51. input = input.Substring(four.Length, input.Length - four.Length);
  52. digits.Add(4);
  53. totalDigits++;
  54. }
  55. }
  56.  
  57. BigInteger number = 0;
  58. StringBuilder numberAsString = new StringBuilder();
  59. for (int i = 0; i < digits.Count; i++)
  60. {
  61. numberAsString.Append(digits[i]);
  62. }
  63.  
  64. BigInteger numberInDec = 0;
  65. int digitPos = digits.Count - 1;
  66. for (int n = 0; n < totalDigits; n++)
  67. {
  68. numberInDec += (BigInteger)digits[n] * Power(5,digitPos);
  69. digitPos--;
  70. }
  71.  
  72. Console.WriteLine(numberInDec);
  73. }
  74.  
  75. private static BigInteger Power(int fund, int pos)
  76. {
  77. BigInteger result = 1;
  78. for (int i = 0; i < pos; i++)
  79. {
  80. result *= fund;
  81. }
  82.  
  83. return result;
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement