Skip to content

Instantly share code, notes, and snippets.

@NicolasFrancaX
Created January 8, 2019 22:13
Show Gist options
  • Save NicolasFrancaX/98b0279ab76ee322e4199237aae08177 to your computer and use it in GitHub Desktop.
Save NicolasFrancaX/98b0279ab76ee322e4199237aae08177 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <stack>
using namespace std;
bool verification(string s) {
stack<char> stq;
for (unsigned int i = 0; i < s.length(); i++) {
if (s[i] == '(') {
stq.push(s[i]);
} else if (s[i] == ')') {
if (stq.empty()) {
return false;
} else {
stq.pop();
}
}
}
return stq.empty();
}
int main() {
string expression;
while (cin >> expression) {
if (verification(expression)) {
cout << "correct" << endl;
} else {
cout << "incorrect" << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment