Codeforces Round #534 (Div. 2)______B. Game with string[字符串,模拟]

Two people are playing a game with a string ss, consisting of lowercase latin letters.

On a player's turn, he should choose two consecutive equal letters in the string and delete them.

For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses.

Your task is to determine which player will win if both play optimally.

Input

The only line contains the string ss, consisting of lowercase latin letters (1≤|s|≤1000001≤|s|≤100000), where |s||s| means the length of a string ss.

Output

If the first player wins, print "Yes". If the second player wins, print "No".

Examples

input

Copy

abacaba

output

Copy

No

input

Copy

iiq

output

Copy

Yes

input

Copy

abba

output

Copy

No

Note

In the first example the first player is unable to make a turn, so he loses.

In the second example first player turns the string into "q", then second player is unable to move, so he loses.

题目大意:给你字符串,让你把这组字符串相同的两个删去,最后谁无法删除谁就失败.

大致思路:和用栈解决括号匹配问题的思路一样,用以个计数器记录一下最后确定输赢就行了.

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;
vector<char> ss;

int main() {
    string ch;
    cin >> ch;
    ss.push_back(ch[0]);
    int k = 1;
    int cnt = 0;
    for(int i = 1; i < ch.size(); i++){
        if(ch[i] == ss[k - 1] && !ss.empty()){
            ss.erase(ss.begin() + k - 1);
            k--;
            cnt += 2;
        }else{
            ss.push_back(ch[i]);
            k++;
        }
    }
    //cout << ss.size() << " " << ch.size();
    if(ss.size() == ch.size()) cout << "No" << endl;
    else{
        if(ss.empty()){
            if((cnt / 2) & 1) cout << "Yes" << endl;
            else cout << "No" << endl;
        }else{
            if((cnt / 2) & 1) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值