# include # include using namespace std; int main ( ) // // LONGEST_WORD is a program which reads input until end-of-file. // // It keeps track of the longest word it has read (defined as // consecutive alphabetic characters), and prints that length at the end. // // The check that the character C is alphabetic uses the fact that // the alphabetic characters satisfy 'A'<=c<='Z' or 'a'<=c<='z'. // { char c; int length = 0; int length_max = 0; while ( true ) { c = cin.get ( ); if ( cin.eof ( ) ) { break; } // // The following check can be replaced by // if ( isalpha ( c ) ) // but then we also have to # include // if ( ( 'A' <= c && c <= 'Z' ) || ( 'a' <= c && c <= 'z' ) ) { length = length + 1; } else { if ( length_max < length ) { length_max = length; } length = 0; } } cout << "Longest word has length " << length_max << ".\n"; return 0; }