"""
1.7 编程基础之字符串 25 最长最短单词
http://noi.openjudge.cn/ch0107/25/
https://blog.csdn.net/hy_696/article/details/106412888
https://blog.csdn.net/m0_43456002/article/details/102729230
LeetCode--最后一个单词的长度(python版)
https://www.jianshu.com/p/e45152efc507
"""
a=input().split()
a=list(a)
lena=len(a)
i=0
max=0
min=99999
while i<lena:
num=len(a[i])
if max<num:
max=num
flagmax=i
if min>num:
min=num
flagmin=i
i+=1
print(a[flagmax])
print(a[flagmin])
C++代码:
/*
1.7编程基础之字符串_25最长最短单词01
http://noi.openjudge.cn/ch0107/25/
*/
#include<iostream>
#include<cstring>
using namespace std;
char c[101],a[101]={0},b[101]={0};
int l1=0,l2=101;
int main()
{
while(cin>>c)
{
if(strlen(c)>l1)
{
strcpy(a,c);
l1=strlen(a);
}
if(strlen(c)<l2)
{
strcpy(b,c);
l2=strlen(b);
}
}
cout<<a<<endl<<b;
return 0;
}