Advertisement
mfgnik

Untitled

Jun 6th, 2020
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cctype>
  5.  
  6. int main() {
  7.     std::string string;
  8.     std::cin >> string;
  9.     std::vector<int64_t> stack;
  10.     int64_t current_number = 0, length = 0, repeats = 1;
  11.     for (auto symbol : string) {
  12.         if (std::isdigit(symbol)) {
  13.             current_number *= 10;
  14.             current_number += symbol - '0';
  15.         } else if (symbol == '[') {
  16.             repeats *= current_number;
  17.             stack.push_back(current_number);
  18.             current_number = 0;
  19.         } else if (symbol == ']') {
  20.             repeats /= stack.back();
  21.             stack.pop_back();
  22.         } else {
  23.             length += repeats;
  24.         }
  25.     }
  26.     std::cout << length << "\n";
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement