Advertisement
STANAANDREY

Untitled

Dec 17th, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define newline '\n'
  3. #define uns unsigned
  4. #define ll long long
  5. #define deb(x) clog << x << ' '
  6. #define debnewL(x) clog << x << newline
  7. using namespace std;
  8. ///*********************
  9.  
  10. string s;
  11. uns it, nrp;
  12.  
  13. inline void PassSpecChars()
  14. {
  15. while(it < s.size() && strchr("[]", s[it]))
  16. {
  17. if (s[it] == '[')
  18. nrp++;
  19. else
  20. nrp--;
  21. it++;
  22. }
  23. }
  24.  
  25. inline string eval()
  26. {
  27. PassSpecChars();
  28. if (it == s.size() - 1)
  29. return "";
  30.  
  31. int nr = 0;
  32. while (it < s.size() && isdigit(s[it]))
  33. {
  34. nr = nr * 10 + int(s[it] - '0');
  35. it++;
  36. }
  37.  
  38. PassSpecChars();
  39. string r = "";
  40. while (it < s.size() && (isalpha(s[it]) or isdigit(s[it])) && s[it] != ']')///2[a2[b]]
  41. {
  42. if (isdigit(s[it]))
  43. {
  44. r += eval();
  45. it++;
  46. continue;
  47. }
  48. r += s[it];
  49. it++;
  50. }
  51.  
  52. string cr = r;
  53. while (--nr)
  54. r += cr;
  55.  
  56. if (it < s.size() - 1 && !nrp)
  57. {
  58. if (isdigit(s[it]))
  59. r += eval();
  60. }
  61. return r;
  62. }
  63.  
  64. int main()
  65. {
  66. getline(cin, s);
  67. do
  68. {
  69. cout << eval();
  70. it++;
  71. }
  72. while (it < s.size());
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement