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;
}
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