-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchaves.cpp
executable file
·44 lines (35 loc) · 937 Bytes
/
chaves.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
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, -1, 0, 1};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
lli N;
cin >> N;
char codigo[N][102];
for(int i = 0; i < N; i++) fgets(codigo[i], 102, stdin);
stack <char> balance;
for(lli i = 0; i < N; i ++){
for(lli j = 0; j < strlen(codigo[i]); j++){
if(codigo[i][j]=='{'){
balance.push('{');
}
else if(codigo[i][j] == '}'){
if(!balance.empty() && balance.top() == '{'){
balance.pop();
}
else{
cout << 'N' << endl;
return 0;
}
}
}
}
if(balance.empty()) cout << 'S' << endl;
else cout << 'N' << endl;
return 0;
}
// Não corrigido ainda.