paranteze intermediar
This commit is contained in:
+45
-1
@@ -4,7 +4,51 @@
|
||||
//([]) nu este corect, şirul ()]( nu este corect.
|
||||
//
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
|
||||
std::string paranteze;
|
||||
std::stack<char> stiva;
|
||||
int ok=1;
|
||||
|
||||
void rotundeInchise(std::string paranteze);
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user