View difference between Paste ID: FG1f2Xg1 and 6MWhg4ZV
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
using namespace std;
3
const int MAX=255;
4
char a[MAX], s[MAX];
5
int k=0;
6
int main() {
7
	cin>>s;
8
	for(int i = 0; i <strlen(s); i++) {
9-
		if ((s[i]=='(' || s[i]=='[' || s[i]=='{') && k<MAX) a[++k]=s[i];
9+
		if (s[i]=='(' || s[i]=='[' || s[i]=='{') a[k++]=s[i];
10-
		if ((s[i]==')' && a[k]=='(' || s[i]==']' && a[k]=='[' || s[i]=='}' && a[k]=='{') && k>=1) k--;
10+
		if ((s[i]==')' && a[k-1]=='(' || s[i]==']' && a[k-1]=='[' || s[i]=='}' && a[k-1]=='{') && k>0)k--;
11
	}
12-
	if (k==0) cout<<"no"; else cout<<"yes";
12+
	if (k==0) cout<<"yes"; else cout<<"no";
13
	return 0;
14
}