Created
January 8, 2019 22:13
-
-
Save NicolasFrancaX/98b0279ab76ee322e4199237aae08177 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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