#include <stdio.h>
#include <string.h>
int i;
int main()
{
int Is_letters(char a);//声明判断字母
int bigword(char str[]);//声明最长单词
int minword(char str[]);//声明最短单词
char str[20010];//str要足够大
int t;
gets(str);
t = strlen(str);
str[t] = ' ';//要在str最后一个字符后面手动补一个‘ ’和\0 不然最后一个单词录不进去
str[t + 1] = '\0';//
for (i = bigword(str); Is_letters(str[i]); i++)//从最大单词的下标开始
{
printf("%c", str[i]);
}
printf("\n");
for (i = minword(str); Is_letters(str[i]); i++)从最小单词的下标开始
{
printf("%c", str[i]);
}
return 0;
}
int Is_letters(char a)//判断是否是字母是返回1不是0
{
if (a >= 'a' && a <= 'z' || a >= 'A' && a <= 'Z')
{
return 1;
}
else
return 0;
}
int bigword(char str[])
{
int flag = 1;//flag=1象征新单词的开始
int len = 0, lenest = 0, place = 0, mplace = 0;
for (i = 0; str[i] != '\0'; i++)
{
if (Is_letters(str[i]))
{
if (flag == 1)
{
flag = 0;
place = i;
}
if (flag == 0)
{
len++;
}
continue;
}
else
{
flag = 1;
if (lenest < len)
{
lenest = len;
mplace = place;
}
len = 0;
}
}
return mplace;
}
int minword(char str[])
{
int len = 0, lenmost = 0,place,mplace,flag=1,count=0;
for (i = 0; str[i] != '\0'; i++)
{
if (Is_letters(str[i]))
{
if (flag == 1)
{
place = i;
flag = 0;
count++;
}
if (flag == 0)
{
len++;
}
continue;
}
else
{
if (count == 1)//将第一个单词的单词数和下标记下
{
lenmost = len;
mplace = place;
}
else if (lenmost > len&&flag ==0)
{
lenmost = len;
mplace = place;
}
flag = 1;
len = 0;
}
}
return mplace;
}