#include<stdio.h>
#include<string.h>
#define M 1000
int main()
{
int low = 0; // 单词的起始下标
int high = 0; // 单词的结束位置
int i; // 循环变量
int count = 0; // 统计最长单词的长度
int temp; // 中间变量
int low_temp;
int high_temp;
char p[M]; // 存储有多个单词的字符指针
gets(p);
for(i = 0; i < strlen(p); i++)
{
temp = 0;
low_temp = i;
while(p[i] != ' ' && p[i] != '\0') // p[i] != 空格
{
temp++;
i++;
}
high_temp = i-1;
if(temp > count)
{
count = temp;
low = low_temp;
high = high_temp;
}
}
for(i = low; i <= high; i++)
{
putchar(p[i]);
}
printf("\n");
return 0;
} |