Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<string.h>
- #include<stack>
- using namespace std;
- bool ParenthesisMatch(string l){
- stack<char>s;
- int flag;
- for(int i=0;i<l.length();i++){
- if(l[i]=='('){
- s.push(l[i]);
- }
- if(l[i]==')'){
- if(s.empty()){
- cout<<"此括号串不匹配"<<endl;
- return false;
- }
- if(s.top()=='('){
- s.pop();
- }else{
- cout<<"此括号串不匹配"<<endl;
- return false;
- }
- }
- }
- if(s.empty()){
- cout<<"此括号串匹配"<<endl;
- }else{
- cout<<"此括号串不匹配"<<endl;
- }
- }
- int main(){
- string t;
- cin>>t;
- ParenthesisMatch(t);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement