Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cctype>
- int main() {
- std::string string;
- std::cin >> string;
- std::vector<int64_t> stack;
- int64_t current_number = 0, length = 0, repeats = 1;
- for (auto symbol : string) {
- if (std::isdigit(symbol)) {
- current_number *= 10;
- current_number += symbol - '0';
- } else if (symbol == '[') {
- repeats *= current_number;
- stack.push_back(current_number);
- current_number = 0;
- } else if (symbol == ']') {
- repeats /= stack.back();
- stack.pop_back();
- } else {
- length += repeats;
- }
- }
- std::cout << length << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement