#include #include char white[] = { '\n', '\r', ' ', '\t', '\f', '\v', }; char punctuation[] = { '.', ',', '\'', '"', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '|', '\\', '[', ']', '{', '}', ':', ';', '<', '>', '?', '/', '`', '~', '=', '_', }; int iswhite( char ch ) { for ( unsigned int i = 0; i < sizeof( white ); ++i ) if ( ch == white[ i ] ) return 1; return 0; } int isletter( char ch ) { if ( ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') return 1; return 0; } int isdigit( char ch ) { if ( ch >= '0' && ch <= '9' ) return 1; return 0; } int ispunctuation( char ch ) { for ( unsigned int i = 0; i < sizeof( punctuation ); ++i ) if ( ch == punctuation[ i ] ) return 1; return 0; } int main( void ) { char ch; long nwhite = 0, nletter = 0, ndigit = 0, npunct = 0, nother = 0, total = 0; while ( std::cin.get( ch ) ) { ++total; if ( iswhite( ch ) ) ++nwhite; else if ( isletter( ch ) ) ++nletter; else if ( isdigit( ch ) ) ++ndigit; else if ( ispunctuation( ch ) ) ++npunct; else ++nother; std::cout << ch; } std::cout << "whitespace: " << nwhite << '\n' << "digits: " << ndigit << '\n' << "letters: " << nletter << '\n' << "punctuation: " << npunct << '\n'; if ( nother ) std::cout << "other chars: " << nother << '\n'; std::cout << "total chars: " << total << '\n'; }