I have a line like this:
A*A**B***A**
I am interested in the sequence of asterisks that are between two different letters, in particular, I need to find the length of the shortest such sequence. For the above line, the answer is of course 2:A**B
I can easily solve this problem using the traditional loop I'm used to:
const string s = "A*A**B***A**";
string::size_type last_letter=-1, min_seq_len=s.size();
for(int i = 0; i < s.size(); i++) {
if(last_letter == -1 || s[i] == '*' || s[i] == s[last_letter]) {
if(s[i] != '*') {
last_letter = i;
}
} else {
min_seq_len = min(min_seq_len, i-last_letter-1);
last_letter = i;
}
}
However, is there a way to do this using the C ++ iterator algorithm library , etc.?
, , , , . , , ++, , ..