Advertisement
CyberN00b

Untitled

Sep 7th, 2022 (edited)
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define LINT long long int
  3. #define ULINT unsigned long long int
  4. #define INF 99999999999
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main(){
  11.     ifstream fin("input.txt");
  12.     string s;
  13.     getline(fin, s);
  14.     int lc = 0, rc = 0, c = 0, index = 0, lli, li = -1, ri = -1, rri;
  15.     bool f = true;
  16.     for (int i = 0; i < s.size(); ++i) {
  17.         if (s[i] == '}') {
  18.             lc++;
  19.             lli = index;
  20.         } else
  21.             if (s[i] == '{') {
  22.                 break;
  23.             }
  24.         index++;
  25.     }
  26.     for (int i = index; i < s.size(); ++i) {
  27.         if (s[i] == '}') {
  28.             c--;
  29.             f = true;
  30.             rc = 0;
  31.             if (ri == -1) {
  32.                 ri = index;
  33.             }
  34.         } else
  35.             if (s[i] == '{') {
  36.                 rc++;
  37.                 if (f && c == 0) {
  38.                     li = index;
  39.                 }
  40.                 c++;
  41.                 f = false;
  42.             }
  43.         index++;
  44.     }
  45.     c -= rc;
  46.     if (lc + rc > 1 || (c > 0 && lc + rc > 0) || (c == 0 && lc + rc == 0) || abs(c) > 1) {
  47.         cout << -1;
  48.         return 0;
  49.     }
  50.     if (c == 1) {
  51.         cout << li + 1;
  52.     } else
  53.         cout << ri + 1;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement