Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- using namespace std;
- bool expcheckPair(string exp)
- {
- stack<char> s;
- char a;
- for (int i = 0; i < exp.length(); i++)
- {
- if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[')
- {
- s.push(exp[i]);
- }
- if (s.empty()) return false;
- switch (exp[i])
- {
- case ')':
- a = s.top();
- s.pop();
- if (a == '{' || a == '[') return false; break;
- case '}':
- a = s.top();
- s.pop();
- if (a == '(' || a == '[') return false; break;
- case ']':
- a = s.top();
- s.pop();
- if (a == '(' || a == '{') return false; break;
- }
- }
- return (s.empty());
- }
- int main() {
- string expression;
- cin >> expression;
- if (expcheckPair(expression)) { cout << "Pair " << endl; }
- else { cout << "Not pair" << endl; }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement