Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<math.h>
- #include<vector>
- #include <queue>
- #include <stack>
- #include <string>
- #include <algorithm>
- #include <climits>
- #include<regex>
- using namespace std;
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- string s, ss,alf = "[a-zA-Z]";
- int maxx = -1, mi, mj, a[10000], st, f, z = 0, b[10000], c[10000];
- int qw=0, qw1 = 0;
- char q=' ';
- regex smatch
- {
- "(\\(|\\{)"
- };
- regex smatch1
- {
- "(\\)|\\})"
- };
- int counter = 0;
- while (getline(cin,s))
- {
- counter++;
- ss = s;
- for (int i = 0; i < ss.length(); i++)
- {
- s = "";
- qw = 0;
- qw1 = 0;
- for (int j = i; j < ss.length(); j++)
- {
- s += ss[j];
- if (regex_match(s, smatch) && j - i >= maxx)
- {
- if (s[0] == 40)
- qw++;
- else
- qw1++;
- }
- else if (regex_match(s, smatch1) && j - i >= maxx)
- {
- if ((q == 40 && s[0] == 125) | (q == 123 && s[0] == 41))
- {
- qw = 0;
- qw1 = 0;
- break;
- }
- else
- {
- if (s[0] == 41 && qw > 0)
- qw--;
- else if (s[0] == 125 && qw1 > 0)
- qw1--;
- else
- {
- qw = 0;
- qw1 = 0;
- break;
- }
- if ((qw == 0) && (qw1 == 0))
- {
- maxx = j - i;
- mi = i + 1;
- mj = j + 1;
- }
- }
- }
- else
- {
- qw = 0;
- qw1 = 0;
- break;
- }
- q = s[0];
- s = "";
- if (maxx >= 0)
- {
- a[z] = i + 1;
- b[z] = j + 1;
- c[z] = counter;
- z++;
- i = mj;
- }
- maxx = -1;
- }
- }
- }
- st = a[0];
- f = b[0];
- int i = 0;
- while(i<z)
- {
- if (abs(b[i] - a[i+1]) == 1 && c[i]==c[i+1])
- {
- //st = b[i];
- f = b[i + 1];
- i++;
- }
- else
- {
- cout << c[i] << ' ' << st << ' ' << f << endl;
- st = a[i+1];
- f = b[i+1];
- i++;
- }
- }//костыль
- }//скоб
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement