Codeforces B. Game with string 1104B Codeforces Round #534 (Div. 2)


Problem link

A solution in c++


#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long ll;
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)
#define mx 10000007
#define mod 1000000007
#define PI acos(-1.0)
int dr[] = {-2,-2,-1,-1,1,1,2,2};
int dc[] = {-1,1,-2,2,-2,2,-1,1};
int main()
{
ll tc, t = 0;
//freopen("/opt/Coding/clion code/output.txt", "w", stdout);
string arr;
cin >> arr;
ll ln = arr.size();
stack <char> stk;
ll cnt = 0;
for(ll i = 0; i < ln; i++){
if(stk.size() and arr[i] == stk.top()){
stk.pop();
cnt++;
}
else
stk.push(arr[i]);
}
if(cnt % 2 == 1) cout << "Yes" << endl;
else cout << "No" << endl;
}

Post a Comment

0 Comments