山东理工大学ACM平台题答案 1180 C语言实验——单词统计

来源:互联网 发布:车辆识别算法研究 编辑:程序博客网 时间:2024/05/01 20:22

C语言实验——单词统计

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

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

输入

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

输出

单词的个数。

示例输入

stable marriage  problem Consists     of Matching members

示例输出

7
 

               

#include <stdio.h>#include <string.h>int main(){    char s[1001], *p;    int count = 0;    gets(s);    p = strtok(s, " ");    while (p != NULL){        count++;        p = strtok(NULL, " ");    }    printf("%d\n", count);

    return 0;}

原创粉丝点击