Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define LINT long long int
- #define ULINT unsigned long long int
- #define INF 99999999999
- using namespace std;
- int main(){
- ifstream fin("input.txt");
- string s;
- getline(fin, s);
- int lc = 0, rc = 0, c = 0, index = 0, lli, li = -1, ri = -1, rri;
- bool f = true;
- for (int i = 0; i < s.size(); ++i) {
- if (s[i] == '}') {
- lc++;
- lli = index;
- } else
- if (s[i] == '{') {
- break;
- }
- index++;
- }
- for (int i = index; i < s.size(); ++i) {
- if (s[i] == '}') {
- c--;
- f = true;
- rc = 0;
- if (ri == -1) {
- ri = index;
- }
- } else
- if (s[i] == '{') {
- rc++;
- if (f && c == 0) {
- li = index;
- }
- c++;
- f = false;
- }
- index++;
- }
- c -= rc;
- if (lc + rc > 1 || (c > 0 && lc + rc > 0) || (c == 0 && lc + rc == 0) || abs(c) > 1) {
- cout << -1;
- return 0;
- }
- if (c == 1) {
- cout << li + 1;
- } else
- cout << ri + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement