C 单词统计 SDUT

自作多情 提交于 2019-12-15 18:05:56

Time Limit: 1000 ms Memory Limit: 65536 KiB


Problem Description

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


Input

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


Output

单词的个数。


Sample Input

stable marriage problem Consists of Matching members


Sample Output

7

Hint

Source


本题 思路 :
在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
   int main()
   {
       char a[101];
       int worde=0,count=0,i;
       gets(a);
       for(i=0;a[i]!='\0';i++)
       {
         if(a[i]==' ') worde = 0;
         else if(worde==0)
         {
             count++;
             worde=1;
         }
       }
     printf("%d\n",count);
       return 0;
   }

运行结果:
stable marriage  problem Consists     of Matching members
7

Process returned 0 (0x0)   execution time : 3.746 s
Press any key to continue.


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!