描述:计算字符串最后一个单词的长度,单词以空格隔开,字符串长度小于5000。(注:字符串末尾不以空格为结尾)
输入描述:输入一行,代表要计算的字符串,非空,长度小于5000。
输出描述:输出一个整数,表示输入字符串最后一个单词的长度。
示例1
输入:hello nowcoder
输出:8
说明:最后一个单词为nowcoder,长度为8
#include "stdio.h"
#include "string.h"
int main()
{
char a[5000];
int num;
while(scanf("%s",a)!=EOF)
num=strlen(a);
printf("%d\n",num);
}
C语言中的scanf的使用_nature_XD的专栏-CSDN博客_scanf在c语言中的作用
#include<stdio.h>
#include<string.h>
int main()
{
char str[5000];
gets(str); // gets()用来从标准设备读入字符并存到参数str所指的内存空间,直到出现换行字符或读到文件尾为止,最后加上NULL作为字符串结束。
int count=0; // 计数变量