-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProblema_1068.cpp
64 lines (55 loc) · 1.04 KB
/
Problema_1068.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
@autor: Victor E. B. Rodrigues;
@data: 24/06/2021;
@nome: Balanço de Parênteses I;
*/
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
int main(){
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
string str;
queue<string> fila;
stack<char> pilha;
while(getline(cin, str)){
if (str == ",")
break;
fila.push(str);
}
while(!fila.empty()){
string equacao = fila.front();
int qtdpe = 0, qtdpd = 0;
if(count(equacao.begin(), equacao.end(), '(') != count(equacao.begin(), equacao.end(), ')')){
cout << "incorrect" << endl;
fila.pop();
continue;
}
for (char chr : equacao){
if(chr == '(' || chr == ')')
pilha.push(chr);
}
while(!pilha.empty()){
if(pilha.top() == ')'){
qtdpd++;
qtdpe--;
}
if(pilha.top() == '('){
qtdpe++;
qtdpd--;
}
if(qtdpd<0)
break;
pilha.pop();
}
if(qtdpd == qtdpe && qtdpd == 0)
cout << "correct" << endl;
else
cout << "incorrect" << endl;
pilha = stack<char>();
fila.pop();
}
return 0;
}