#include <iostream> #include <string> using namespace std; class Stack { private: int Top; public: Stack(int n); void Push(); void Pop(); int GetSize(); }; Stack::Stack(int n) { Top = 0; } void Stack::Push() { Top++; } void Stack::Pop() { Top--; } int Stack::GetSize() { return Top; } int main() { int TestCase; cin >> TestCase; while (TestCase) { TestCase--; Stack S(0); string sInput; cin >> sInput; for (int i = 0; i < sInput.size(); i++) { if (sInput[i] == '(') S.Push(); else if (sInput[i] == ')') S.Pop(); else break; if(S.GetSize() == -1) break; } if (S.GetSize() == 0) cout << "YES" << endl; else cout << "NO" << endl; } }
# include < iostream > # include < vector > using namespace std ; int main ( ) { vector < int > Stick ; Stick . push_back ( 64 ) ; int Target ; cin > > Target ; int Last = 0 ; while ( true ) { if ( Target = = 64 ) break ; int Sum = 0 ; for ( int i = 0 ; i < Stick . size ( ) ; i + + ) Sum + = Stick [ i ] ; if ( Target = = Sum ) break ; else if ( Target < Sum ) { Stick [ Last ] / = 2 ; Sum = 0 ; for ( int i = 0 ; i < Stick . size ( ) ; i + + ) Sum + = Stick [ i ] ; if ( Target < = Sum ) continue ; else Stick . push_back ( Stick [ Last + + ] ) ; } } cout < < Stick . size ( ) ; ...
댓글
댓글 쓰기