Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include<stack>#include<stdio.h>#include<string.h>using namespace std;char str[100001];int res[100001] = { 0 };int main(){int max = 0;scanf("%s", str);stack<int>s;int len = strlen(str);for (int i = 0; i < len; ++i){if (str[i] == '('){s.push(i + 1);max = i + 1;}else if (!s.empty()){res[s.top()] = i + 1;s.pop();}}for (int i = 1; i <= max ; ++i){if(res[i]!=0)printf("%d %d\n", i, res[i]);}