#include <iostream>
using namespace std;
int fun(const char *str)
{
int flag = 0;
int count = 0;
for(int i=0; str[i] != '\0'; ++i)
{
if( (str[i]>='a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') )
{
if(0 == flag)
{
count++;
flag = 1;
}
}
else
{
flag = 0;
}
}
return count;
}
void main()
{
const char *s = " Liu @a @Fang 123 Shi Jiang zho ng@#$ 456767 ^& ";
cout << s <<endl;
cout << fun(s) <<endl;
}
【每日一题】2012.5.26:查找字符串中单词的个数
最新推荐文章于 2021-12-19 12:01:10 发布