#include <iostream>                                // Ex25
#include <string>
using namespace std;
int main() {
    string line, word;
    string::size_type p, words = 0;
    for ( ;; ) {                                // scan lines from a file
        getline( cin, line );                    // read entire line, but not newline
      if ( cin.eof() ) break;                    // end-of-file ?
        line += '\n';                            // add newline character as sentinel character
        for ( ;; ) {                            // scan words off line
            p =line.find_first_not_of(" \t\n");    // find position of 1st non-whitespace character
          if ( p == string::npos ) break;        // any characters left ?
            line = line.substr( p );            // remove leading whitespace
            p = line.find_first_of(" \t\n");    // find position of 1st whitespace character
            word = line.substr( 0, p );            // extract word from start of line
            words += 1;                            // count word
            line = line.substr( p );            // delete word from line
        } // for
    } // for
    cout << "words: " << words << endl;
}
