#include using namespace std; template class Stack { public: Stack (int m); ~Stack (); int StackIsFull(); int StackIsEmpty(); void Push(x e); void Pop(x& e); void PrintStack(); private: int maxsize; int top; x *p; }; template Stack::Stack(int m){ maxsize = m; top = -1; p = new x[maxsize]; } template Stack::~Stack(){ delete [] p; } template int Stack::StackIsFull(){ if (top == maxsize - 1) return 1; return 0; } template int Stack::StackIsEmpty(){ if (top == -1) return -1; return 0; } template void Stack::Push(x e){ if (!StackIsFull()){ top++; p[top] = e; } } template void Stack::Pop(x &e){ if (!StackIsEmpty()){ e = p[top]; top--; } } template void Stack::PrintStack(){ x e; if (!StackIsEmpty()){ Pop(e); PrintStack(); cout << e << endl; Push(e); } } template void match (Stack &s, char e, int& balanced) { x a; if (s.StackIsEmpty()) balanced = 0; else{ s.Pop(a); if (e != a) balanced = 0; } } int balance(char* f) { int balanced = 1, i = 0; Stack s(64); while(balanced && f[i] != '\0') { if (f[i] == '(' || f[i] == '{' || f[i] == '[') s.Push(f[i]); else{ if (f[i] == ')') match(s, '(', balanced); else if (f[i] == '}') match(s, '{', balanced); else if (f[i] == ']') match(s, '[', balanced); } i++; } if (!s.StackIsEmpty()) balanced = 0; return balanced; } int main(){ char f[64]; cin.getline(f,64); int b; b = balance (f); cout << b; return 0; }