程式碼:
# include <iostream>
using namespace std ;
int main() {
char chara = ' ' ;
char line[10000] = "" ;
int spacenum = 0 ;
bool prevwordisspace = false ;
while ( ! cin.eof() ) {
gets( line ) ;
spacenum = 0 ;
for ( int i = 0 ; line[i] != '\0' ; i ++ ) {
if ( line[i] == ' ' ) {
if ( !prevwordisspace )
spacenum ++ ;
prevwordisspace = true ;
} // if
else
prevwordisspace = false ;
} // for
if ( line[0] == '\0' )
printf( "0\n" ) ;
else if ( line[0] == ' ' )
printf( "%d\n", spacenum ) ;
else
printf( "%d\n", spacenum + 1 ) ;
} // while
return 0 ;
} // main()
...不知道該說什麼了...