diff --git a/tema_3/paranteze.cpp b/tema_3/paranteze.cpp index 529d97b..2272e02 100644 --- a/tema_3/paranteze.cpp +++ b/tema_3/paranteze.cpp @@ -4,7 +4,51 @@ //([]) nu este corect, şirul ()]( nu este corect. // #include +#include + +std::string paranteze; +std::stack stiva; + int ok=1; + +void rotundeInchise(std::string paranteze); int main() { + std::cout <<"sir de paranteze = "; + std::cin >> paranteze; + + bool acolada, patrata; + + for (int i = 0; i < paranteze.size(); i++) { + if (paranteze[i] == '{') { + stiva.push('{'); + } + else if (paranteze[i] == '[') { + stiva.push('['); + } + else if (paranteze[i] == '(') + stiva.push('('); + + else { + if (paranteze[i] == ')' || paranteze[i] == ']' || paranteze[i] == '}') { + if(!stiva.empty()){ + stiva.pop(); + } + else { + std::cout<<"prea multe paranteze deschise \n"; + ok=0; + break; + } + } + } + } + + if (ok && stiva.empty()) { + std::cout << "toate sunt închise"; + } + else { + std::cout << "nu sunt închise"; + } + return 0; + }