错误总结:Stack over flow!!
char类型的栈 数据范围很小,无法存放几百几千个
在定义栈的时候 应写为 stack<int> s;
AC代码:
#include <iostream> #include<stack> #include<cstring> #include<bits/stdc++.h> using namespace std; const int MAX=60000; stack<int> s; //stack<char> s; <--Wrong!!!!! char类型的栈数据范围很小,无法存放几百几千个 int main() { int flag=0; int R[MAX]; memset(R,0,sizeof(R)); char p; int i=0; while(scanf("%c",&p)==1&&p!=10){ i++; if(p=='('){ s.push(i); } if(p==')'){ if(s.empty()){ cout<<"No"<<endl; return 0; } else{ int t=s.top(); s.pop(); R[t]=i; } } } if(s.empty()){ cout<<"Yes"<<endl; for(int j=1;j<=i;j++){ if(R[j]!=0){ cout<<j<<" "<<R[j]<<endl; } } } return 0; }