Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include<math.h>
  3. #include<vector>
  4. #include <queue>
  5. #include <stack>
  6. #include <string>
  7. #include <algorithm>
  8. #include <climits>
  9. #include<regex>
  10. using namespace std;
  11.  
  12.  
  13. int main()
  14. {
  15. freopen("input.txt", "r", stdin);
  16. freopen("output.txt", "w", stdout);
  17.  
  18. string s, ss,alf = "[a-zA-Z]";
  19. int maxx = -1, mi, mj, a[10000], st, f, z = 0, b[10000], c[10000];
  20. int qw=0, qw1 = 0;
  21. char q=' ';
  22. regex smatch
  23. {
  24. "(\\(|\\{)"
  25. };
  26. regex smatch1
  27. {
  28. "(\\)|\\})"
  29. };
  30. int counter = 0;
  31. while (getline(cin,s))
  32. {
  33. counter++;
  34. ss = s;
  35. for (int i = 0; i < ss.length(); i++)
  36. {
  37. s = "";
  38. qw = 0;
  39. qw1 = 0;
  40. for (int j = i; j < ss.length(); j++)
  41. {
  42. s += ss[j];
  43. if (regex_match(s, smatch) && j - i >= maxx)
  44. {
  45. if (s[0] == 40)
  46. qw++;
  47. else
  48. qw1++;
  49. }
  50. else if (regex_match(s, smatch1) && j - i >= maxx)
  51. {
  52. if ((q == 40 && s[0] == 125) | (q == 123 && s[0] == 41))
  53. {
  54. qw = 0;
  55. qw1 = 0;
  56. break;
  57. }
  58. else
  59. {
  60. if (s[0] == 41 && qw > 0)
  61. qw--;
  62. else if (s[0] == 125 && qw1 > 0)
  63. qw1--;
  64. else
  65. {
  66. qw = 0;
  67. qw1 = 0;
  68. break;
  69. }
  70. if ((qw == 0) && (qw1 == 0))
  71. {
  72. maxx = j - i;
  73. mi = i + 1;
  74. mj = j + 1;
  75. }
  76. }
  77. }
  78. else
  79. {
  80. qw = 0;
  81. qw1 = 0;
  82. break;
  83. }
  84. q = s[0];
  85. s = "";
  86. if (maxx >= 0)
  87. {
  88. a[z] = i + 1;
  89. b[z] = j + 1;
  90. c[z] = counter;
  91. z++;
  92. i = mj;
  93. }
  94. maxx = -1;
  95. }
  96. }
  97. }
  98. st = a[0];
  99. f = b[0];
  100. int i = 0;
  101. while(i<z)
  102. {
  103. if (abs(b[i] - a[i+1]) == 1 && c[i]==c[i+1])
  104. {
  105. //st = b[i];
  106. f = b[i + 1];
  107. i++;
  108. }
  109. else
  110. {
  111. cout << c[i] << ' ' << st << ' ' << f << endl;
  112. st = a[i+1];
  113. f = b[i+1];
  114. i++;
  115. }
  116. }//костыль
  117. }//скоб
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement