-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpressoes.cpp
More file actions
executable file
·42 lines (35 loc) · 849 Bytes
/
Copy pathexpressoes.cpp
File metadata and controls
executable file
·42 lines (35 loc) · 849 Bytes
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
#include <cstdio>
#include <iostream>
#include <stack>
#include <cstring>
#include <stdlib.h>
using namespace std;
stack <char> pilha;
bool compare (char c) ;
int main () {
int n;
char c;
cin >> n;
c = getc (stdin);
for (int i = 0; i < n; i++) {
c = getc (stdin);
while (c != '\n') {
if (!pilha.empty () && compare (c)) pilha.pop ();
else pilha.push (c);
c = getc (stdin);
}
if (pilha.empty ())
printf("S\n");
else {
printf("N\n");
while (!pilha.empty ())
pilha.pop ();
}
}
}
bool compare (char c) {
if (c == '}' && pilha.top () == '{') return true;
if (c == ')' && pilha.top () == '(') return true;
if (c == ']' && pilha.top () == '[') return true;
return false;
}