最大最小单词简略版(The Biggest and Smallest Words)
编写程序找出一组单词中“最小”单词和“最大”单词。
用户输入单词后,程序根据字典顺序决定排在最前面和最后面的单词。
当用户输入4个字母的单词时,程序停止读入。假设所有单词都不超过20个字母。
输出范例1:
```Enter word: dog
Enter word: zebra
Enter word: rabbit
Enter word: catfish
Enter word: walrus
Enter word: cat
Enter word: fish
Smallest word: cat
Largest word zebra
#include <stdio.h>
int main ()
{
int i=1,x=1,y,count[100]={0};
char ch,a[100],Smallest_word,Largest_word;
int record_small,record_large;
L:
printf("Enter word:"); //读入单词
ch=getchar();
for(;ch!='\n';++i)
{
a[i]=ch;
ch=getchar();
}
--i;
count[x]=i;
++x;
if((i-count[x-2])!=4)
{
++i;
goto L;
}
else //判断最大最小
{
y=x;
Smallest_word=a[1];
Largest_word=a[1];
for(x=0;x<y;++x) //判断最小
{
if(Smallest_word<a[(count[x]+1)])
{
Smallest_word=Smallest_word;
record_small=x;
}
else {
Smallest_word=a[(count[x]+1)];
record_small=x;
}
}
for(x=0;x<y;++x) //判断最大
{
if(Largest_word>a[(count[x]+1)])
{
Largest_word=Largest_word;
record_large=x;
}
else {
Largest_word=a[(count[x]+1)];
record_large=x;
}
}
}
printf("adad:%c%c",Smallest_word,Largest_word);
printf("Smallest word:"); //输出
for(x=count[record_small]+1;x<=count[record_small+1];++x)
printf("%c",a[x]);
```c
```c
```
printf("\nLargest word:");
for(x=count[record_large]+1;x<=count[record_large+1];++x)
printf("%c",a[x]);
return 0;
}
无输出结果!!1