Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:51
Show Gist options
  • Save pinglunliao/b6eccf97b3ced30363ad to your computer and use it in GitHub Desktop.
Save pinglunliao/b6eccf97b3ced30363ad to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
string str;
bool curLetter;
bool preLetter;
while( getline(cin, str ) )
{
short wordCount = 0;
preLetter = false;
int len = str.length();
for(int i = 0; i < len; i++)
{
curLetter = (str[i] >= 'a' && str[i] <= 'z')
|| (str[i] >= 'A' && str[i] <= 'Z');
if(preLetter && !curLetter)
wordCount++;
preLetter = curLetter;
}
if(curLetter)
wordCount++;
cout << wordCount << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment