问题 1505: [蓝桥杯][算法提高VIP]单词个数统计
题目描述
编写一个程序,输入一个字符串(长度不超过80),然后统计出该字符串当中包含有多少个单词。例如:字符串“this is a book”当中包含有4个单词。
输入
输入一个字符串,由若干个单词组成,单词之间用一个空格隔开。
输出
输出一个整数,即单词的个数。
样例输入
this is a book
样例输出
4
#include <iostream>
#include <string.h>
#include <cstdio>
#include <cctype>
using namespace std;
int main()
{
char c[88];
int co = 0;
gets(c);
for(int i = 0;i<strlen(c);i++){
if(c[i] == ' '){
co++;
}
}
cout<<co+1;
return 0;
}