Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <vector>
- #include <stack>
- bool areBracketsCorrect (std::vector <char> vec1){
- std::stack <char> st;
- bool isEmpty;
- for(size_t i = 0; i < vec1.size(); i++){
- if(vec1[i] == '('){
- st.push(vec1[i]);
- }
- }
- for(size_t j = 0; j < vec1.size(); j++){
- if(vec1[j] == ')'){
- st.pop();
- }
- }
- if(st.empty() == 1){
- isEmpty = 1;
- } else {
- isEmpty = 0;
- }
- return isEmpty;
- }
- int main (){
- std::string expression;
- std::cin >> expression;
- std::istringstream exprStream(expression);
- std::vector <char> vecOfChar;
- char currentChar;
- while(exprStream >> currentChar){
- vecOfChar.push_back(currentChar);
- }
- if(areBracketsCorrect(vecOfChar) == 1){
- std::cout << "correct" << std::endl;
- } else {
- std::cout << "incorrect" << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement