From 4edcc17a6b8ad0933e9e9e643e5620098f6cde05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20Tof=C4=83nel?= Date: Fri, 12 Dec 2025 13:00:48 +0200 Subject: [PATCH] paranteze intermediar --- tema_3/paranteze.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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; + }