返回顶部

括号匹配(绕线)

D. Alternating Current

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
#include<stack>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define eps 1e-9
#define PIE acos(-1)
#define cl(a,b) memset(a,b,sizeof(a))
#define fastio ios::sync_with_stdio(false);cin.tie(0);
#define lson l , mid , ls
#define rson mid + 1 , r , rs
#define ls (rt<<1)
#define rs (ls|1)
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define lowbit(x) (x&(-x))
#define sqr(a) a*a
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int, int>
#define dd(x) cout << #x << " = " << (x) << ", "
#define de(x) cout << #x << " = " << (x) << "\n"
#define endl "\n"
using namespace std;
const int N=1e5+7;
stack<char>s;

int main()
{
    char ss[N];
    scanf("%s",ss);
    int n=strlen(ss);
    int ok=1;
    rep(i,0,n){
        if(s.empty())s.push(ss[i]);
        else if(s.top()==ss[i])s.pop();
        else s.push(ss[i]);
    }
    if(s.empty())cout<<"Yes"<<endl;
    else cout<<"No"<<endl; 
    return 0;
}
View Code

 

posted @ 2018-11-04 22:16  牛奶加咖啡~  阅读(95)  评论(0编辑  收藏  举报