单词统计 SDUT

C语言实验——单词统计

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

从键盘输入一行字符(长度小于100),统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。

Input

输入只有一行句子。仅有空格和英文字母构成。

Output

单词的个数。

Sample Input

stable marriage problem Consists of Matching members

Sample Output

7

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char a[10000];
int f=0,i,n;
int z=0;
gets(a);
n=strlen(a);
for(i=0;i<n;i++)
{
if(f0)
{
if(a[i]>=‘a’&&a[i]<=‘z’||a[i]>=‘A’&&a[i]<=‘Z’)
{
f=1;
z++;
}
}
else
{
if(f
1&&a[i]==’ ')
{
f=0;
}
}
}
printf("%d\n",z);
return 0;
}

/***************************************************
User name: jk180233李清璇
Result: Accepted
Take time: 0ms
Take Memory: 164KB
Submit time: 2019-01-02 16:17:48
****************************************************/

猜你喜欢

转载自blog.csdn.net/weixin_43892738/article/details/85622477