Assignment 4
Write a program that finds the shortest and the longest names from a list of English names. The program first reads the number of English names, and then reads the list of English names. The program outputs the shortest and the longest names. If there are multiple shortest names of the same length, sort those names in alphabetical order, and output the first English name. For example, if the shortest names are
Adey Bell Alex Bill
Sorting the above in alphabetical order leads to
Adey Alex Bell Bill
The program should output Adey as the shortest name. Similarly, if there are multiple longest names of the same length, sort those names in alphabetical order, and output the last English name. For example, if the longest names are
Zitella Yalonda Zabrina Yolande
Sorting the above in alphabetical order leads to
Yalonda Yolande Zabrina Zitella
The program should output Zitella as the longest English name. A complete example is given below.
Program Input
Enter the number of English names: 6
Enter English names: Bill Camel Alex Alexandrina Zitella Yolande
Program Output
Shortest name: Alex
Longest name: Alexandrina
- Your solution should be based on the code template.
- You probably need to add 10~45 lines to the code template for completing this assignment.
- More input-output samples.