braketmatch
This commit is contained in:
35
Stack/appliance/braket-match.cpp
Normal file
35
Stack/appliance/braket-match.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#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;
|
||||||
|
}
|
BIN
Stack/appliance/braket-match.exe
Normal file
BIN
Stack/appliance/braket-match.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user