Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- char s[100010];
- int poz;
- string eval();
- string rez()
- {
- string str;
- if(s[poz] == '[')
- {
- poz++;
- str = eval();
- poz++;
- return str;
- }
- while(s[poz] >= 'a' && s[poz] <= 'z')
- str.push_back(s[poz++]);
- return str;
- }
- string eval()
- {
- string str = rez();
- while(isdigit(s[poz]) || isalpha(s[poz]))
- {
- if(s[poz] >= 'a' && s[poz] <= 'z')
- {
- string str1 = rez();
- str.append(str1);
- }
- else
- {
- int nr = 0;
- while(s[poz] >= '0' && s[poz] <= '9')
- nr = nr * 10 + (s[poz++] - '0');
- string str1 = rez();
- for(int i = 1 ; i <= nr ; i++)
- str.append(str1);
- }
- }
- return str;
- }
- int main()
- {
- cin >> s;
- cout << eval();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement