VJ_Alternating Current_stack

 

 

 

 

//
#include<bits/stdc++.h>
using namespace std;

stack<char> sk;

int main()		// s.erase()  写法会超时 
{
    string s;
    int i;

    while( getline( cin,s ) )
    {
        if( !sk.empty() ) sk.pop();

        for( i=0;i<s.size();i++ )		// is sk.empty() not s.empty() 
        {						
            if( sk.empty() ) { sk.push( s[i] ); continue; }

            if( sk.top()==s[i] ) 	sk.pop();
            else 					sk.push( s[i] ); 
        }
        if( sk.empty() )    cout<<"Yes"<<endl;
        else                cout<<"No"<<endl;
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_63173957/article/details/124406066