Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. //214
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <math.h>
  5. #include <string>
  6. #include <algorithm>
  7. #include <climits>
  8. #include <regex>
  9. using namespace std;
  10.  
  11.  
  12.  
  13.  
  14. int main()
  15. {
  16.     freopen("input.txt", "r", stdin);
  17.     freopen("output.txt", "w", stdout);
  18.     smatch res;
  19.     string s;
  20.  
  21.     regex regular("(\\(\\#*\\)|\\{\\#*\\})");
  22.  
  23.     int i = 1;
  24.     while (getline(cin, s))
  25.     {
  26.  
  27.         int k = 1;
  28.         while (regex_search(s, res, regular))
  29.         {
  30.             s[res.position()] = '#';
  31.             int c = res.position();
  32.             while (s[c] == '#')
  33.                 c++;
  34.             s[c] = '#';
  35.  
  36.         }
  37.         int b = 0;
  38.         int e = -1;
  39.  
  40.         for (int j = 0;j < s.length();j++)
  41.         {
  42.             if (s[j] == '#')
  43.                 if (e - b < 0)
  44.                 {
  45.                     b = j;e = j;
  46.                 }
  47.                 else
  48.                     e++;
  49.             else
  50.                 if (e - b >= 0)
  51.                 {
  52.                     cout << i << " " << b + 1 << " " << e + 1 << endl;
  53.                     b = 0;e = -1;
  54.                 }
  55.         }
  56.         if (e - b >= 0)
  57.             cout << i << " " << b + 1 << " " << e + 1<< endl;
  58.  
  59.  
  60.  
  61.         cout << endl;
  62.         i++;
  63.     }
  64.  
  65.  
  66.  
  67.  
  68.     return 0;
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement