Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. //215
  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 m;
  20.  
  21.     regex regular("(\\(\\#*\\)|\\{\\#*\\})");
  22.  
  23.     int i = 1;
  24.     while (getline(cin, m))
  25.     {
  26.         string s;
  27.         vector <int> g(0);
  28.        
  29.         for (int j = 0;j < m.length();j++)
  30.         {
  31.             int a = (int)m[j];
  32.             if ((a == 40) || (a == 41) || (a == 123) || (a == 125))
  33.             {
  34.                 g.push_back(j);
  35.                 s = s + m[j];
  36.             }
  37.         }
  38.  
  39.  
  40.  
  41.  
  42.         while (regex_search(s, res, regular))
  43.         {
  44.             s[res.position()] = '#';
  45.             int c = res.position();
  46.             while (s[c] == '#')
  47.                 c++;
  48.             s[c] = '#';
  49.  
  50.         }
  51.         int b = 0;
  52.         int e = -1;
  53.  
  54.         for (int j = 0;j < s.length();j++)
  55.         {
  56.             if (s[j] == '#')
  57.                 if (e - b < 0)
  58.                 {
  59.                     b = j;e = j;
  60.                 }
  61.                 else
  62.                     e++;
  63.             else
  64.                 if (e - b >= 0)
  65.                 {
  66.                     cout << i << " " << g[b] + 1 << " " << g[e] + 1 << endl;
  67.                     b = 0;e = -1;
  68.                 }
  69.         }
  70.         if (e - b >= 0)
  71.             cout << i << " " << g[b] + 1 << " " << g[e] + 1 << endl;
  72.  
  73.  
  74.  
  75.         cout << endl;
  76.         i++;
  77.     }
  78.  
  79.  
  80.  
  81.  
  82.     return 0;
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement