while (scanf("%s", str) != EOF) { int len = strlen(str); bool flag = true; for (int i = 0; i < len; i++) { if (str[i] == '(' || str[i] == '[' || str[i] == '{') S.push(str[i]); else { if (S.empty()) { flag = false; break; }
char top = S.top(); S.pop();
if (str[i] == ')' && top != '(') { flag = false; break; } if (str[i] == ']' && top != '[') { flag = false; break; } if (str[i] == '}' && top != '{') { flag = false; break; } } } stack<char>().swap(S);
if (flag) printf("sucessful\n"); else printf("fail\n"); } }