描述
给以行句子,写一个程序判断它有几个单词。
输入
输入占一行,行尾有空格,并且只含有大写字母和小写字母和空格。
输出
单词的个数。
例如:
printf("%d\n"),num;
例如:
printf("%d\n"),num;
输入样例
General game players are systems able to
输出样例
7
#include<iostream>
#include<stdio.h>#include<string.h>
using namespace std;
int main()
{
int x,i,sum;
char str[256];
gets (str);
x=strlen(str);
sum=0;
for(i=1;i<x;i++)
{
if(str[i]==' '&&str[i-1]!=' ')
{
sum=sum+1;
}
}
cout<<sum<<endl;
return 0;
}