36 lines
632 B
C++
36 lines
632 B
C++
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <stack>
|
|
using namespace std;
|
|
|
|
void isMatch(const string& s){
|
|
stack<int> t;
|
|
//bool error = false;
|
|
for(int i = 0; i < s.length(); i++){
|
|
if(s[i] == '('){
|
|
t.push(i);
|
|
}
|
|
if(s[i] == ')'){
|
|
try{
|
|
if(t.empty()) throw std::runtime_error("Error: Braket \" ) \" No Match");
|
|
t.pop();
|
|
}
|
|
catch(const runtime_error& e){
|
|
cout << e.what() << endl;
|
|
//error = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if(t.empty()) cout << "Match" << endl;
|
|
else cout << "Error: Braket \" ( \" No Match" << endl;
|
|
}
|
|
|
|
int main(){
|
|
string s;
|
|
cin >> s;
|
|
isMatch(s);
|
|
return 0;
|
|
}
|