fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <boost/algorithm/string.hpp>
  4.  
  5. size_t word_count( const string & text )
  6. {
  7. vector<string> words;
  8. boost::split( words, text, boost::is_any_of(" :-,."), boost::token_compress_on );
  9. return std::accumulate( words.begin(), words.end(), 0,
  10. []( size_t n, const string & s ) -> size_t { return n + (s.size() % 2 == 0 ? 1 : 0);} );
  11. }
  12.  
  13. int main() {
  14. cout << word_count("test test abc asdf") << std::endl; //prints 3
  15. cout << word_count("AAA A AAA") << std::endl; //prints 0
  16. }
Success #stdin #stdout 0s 3288KB
stdin
Standard input is empty
stdout
3
0