基本思想:
碰到"(“存入堆栈
碰到”)“弹出堆栈顶端的”("
#include "stdafx.h"
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main(){
string s = "(1+5)+3+(3()";
stack<char> st;
for(int i = 0;i<s.length();i++){
char c = s[i];
if(c=='('){
st.push(c);
}else{
if(c==')'){
if(st.empty()){
cout<<"no ( ,still have )"<<endl;
break;
}else{
st.pop();
}
}
}
}
if(!st.empty()){
cout<<"no ) , still have ("<<endl;
}
system("pause");
return 0;
}