ABC words: Difference between revisions

Content added Content deleted
(Added C++ solution)
m (Simplified C++ code)
Line 159:
 
bool is_abc_word(const std::string& word) {
size_tbool a = std::string::nposfalse;
size_tbool b = std::string::nposfalse;
for (size_tchar posch = 0, n =: word.size(); pos < n; ++pos) {
switch (word[pos]ch) {
case 'a':
//if record position of first '(!a')
if ( a == std::string::npos)true;
a = pos;
break;
case 'b':
if (!b == std::string::npos) {
// fail if we haven't seen 'a' yet
if (!a == std::string::npos)
return false;
//b record= position of first 'b'true;
b = pos;
}
break;
case 'c':
// succeed iff we've seen 'b' already
return b != std::string::npos;
}
}