#include <iostream>
using namespace std;
int main()
{
char str[1024];
gets_s(str);
int count(0);
int i, word(0);
char c;
for (i = 0; (c = str[i]) != '\0';++i)
{
if (c == ' ')
{
word = 0;
}
else if (word == 0)
{
word = 1;
count++;
}
}
cout << count;
return 0;
}
【算法题】统计字符串单词个数
最新推荐文章于 2022-02-22 20:50:12 发布