Monday, April 1, 2019

B. Alternating Current

B. Alternating Current

Link for the problem: B. Alternating Current


SOLUTION:

This is a direct and easy implementation of stack.
See the code for more explanation.


CODE:

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
    string s;
    int i,k,l;
    cin>>s;
    l=s.length();
    vector<char> v;
    v.push_back(s[0]);
    for(i=1;i<l;i++)
    {
        if(s[i]==v[v.size()-1])
        v.pop_back();
        else
        v.push_back(s[i]);
    }
    if(v.size())
    cout<<"No";
    else
    cout<<"Yes";
    return 0;

}

No comments:

Post a Comment

CHEFST: Chef and the stones

CHEFST: Chef and the stones Link for the problem:  CHEFST SOLUTION: For a given max possible no of stones that can be removed from ea...