找出總共有幾個Word。
[C++](2ms, 754KB)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cctype> | |
using namespace std; | |
int main() | |
{ | |
string s; | |
while( getline( cin, s ) ) | |
{ | |
int num = 0; | |
bool word = 0; | |
for( int i = 0 ; i < s.length(); i++ ) | |
{ | |
if( isalpha( s[i] ) ) | |
{ | |
if( !word ) | |
{ | |
word = 1; | |
num++; | |
} | |
} | |
else | |
word = 0; | |
} | |
cout << num << endl; | |
} | |
return 0; | |
} |
0 意見:
張貼留言