点击查看代码
#include<bits/stdc++.h>
using namespace std;
stack<int>s;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
string m;cin>>m;cin.ignore();
for(int i=0;i<m.size();i++)
{
if(m[i]=='(') s.push(i);
else
{
if(s.empty())
{
cout<<"error"<<'\n';
return 0;
}
else
{
cout<<s.top()<<" "<<i<<'\n';
s.pop();
}
}
}
return 0;
}

浙公网安备 33010602011771号