Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <string>
- using namespace std;
- string findresult(std::string& input) {
- string result = "";
- int maxDepth = -1;
- int currentDepth = 0;
- bool flag = false;
- for (char c : input) {
- if (c == '(' || c == '{' || c == '[') {
- currentDepth++;
- if (currentDepth > maxDepth) {
- flag = false;
- maxDepth = currentDepth;
- result = "";
- }
- }
- else if (c == ')' || c == '}' || c == ']') {
- if (currentDepth == maxDepth) {
- flag = true;
- }
- currentDepth = 0;
- }
- else if (currentDepth == maxDepth and !flag) {
- result += c;
- }
- cout << result << endl;
- }
- return result;
- }
- int main()
- {
- ifstream input("input.txt");
- ofstream output("output.txt");
- string read = "";
- string cur = "";
- while (!input.eof()) {
- getline(input, cur);
- read += cur;
- cur = "";
- }
- string result = findresult(read);
- output << result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement