#include <stdio.h>
#include <string.h>
char* isBalanced(char* s) {
char stack[10];
int top = -1;
for (int i = 0; i < len / 2; i++) {
if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
stack[++top] = s[i];
}
}
for (int i = len - 1; i > len / 2; i--) {
char c = stack[top --];
if ((s[i] == ')' && c == '(') ||
(s[i] == ']' && c == '[') ||
(s[i] == '}' && c == '{')) {
} else {
return "NO";
}
}
return "YES";
}
int main()
{
char *s = "{[()]}";
isBalanced(s);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmNoYXIqIGlzQmFsYW5jZWQoY2hhciogcykgewogICAgaW50IGxlbiA9IHN0cmxlbihzKTsKICAgIGNoYXIgc3RhY2tbMTBdOwogICAgaW50IHRvcCA9IC0xOwogICAgCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxlbiAvIDI7IGkrKykgewogICAgICAgIGlmIChzW2ldID09ICcoJyB8fCBzW2ldID09ICdbJyB8fCBzW2ldID09ICd7JykgewogICAgICAgICAgICBzdGFja1srK3RvcF0gPSBzW2ldOwogICAgICAgIH0gCiAgICAgICAgCiAgICB9CiAgICAKICAgIGZvciAoaW50IGkgPSBsZW4gLSAxOyBpID4gbGVuIC8gMjsgaS0tKSB7CiAgICAgICAgY2hhciBjID0gc3RhY2tbdG9wIC0tXTsKICAgICAgICBpZiAoKHNbaV0gPT0gJyknICYmIGMgPT0gJygnKSB8fAogICAgICAgICAgICAoc1tpXSA9PSAnXScgJiYgYyA9PSAnWycpIHx8CiAgICAgICAgICAgIChzW2ldID09ICd9JyAmJiBjID09ICd7JykpIHsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuICJOTyI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICB9CiAgICAKICAgIHJldHVybiAiWUVTIjsKCn0KCmludCBtYWluKCkKewogICAgcHJpbnRmKCJIZWxsbyBXb3JsZFxuIik7CiAgICAKICAgIGNoYXIgKnMgPSAie1soKV19IjsKICAgIAogICAgaXNCYWxhbmNlZChzKTsKCiAgICByZXR1cm4gMDsKfQ==