In this program I have a string which I pass as a parameter to a function. I want the function to erase all adjacent letters from a string containing only letters from a-z, always ordered alphabetically. For example if i enter aaabbccd, the program ought to output ad. I want to ask why the program stops working?
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<char> rez;
string reduce_string(string s)
{
for(int i=0; i<s.length()-1; i++)
{
if(s[i]==s[i+1])
{
s[i]=s[i+1]='0';
s.erase(i);
s.erase(i+1);
}
}
return s;
}
int main()
{
string s;
cin >> s;
cout<<reduce_string(s);
return 0;
}