-->
当前位置:首页 > 题库

PROGRAMMING:Compare the size of 10 strings and output from small to large

Luz5年前 (2021-05-10)题库437
This problem requires the preparation of a function to realize the sorting of strings. The specific input and output of the program are as follows:
###Input format:
Input 10 strings in turn, and use newline to distinguish them
###Output format:
Output a sorted string
###Input example:
Here is a set of inputs. For example:
```in
zhao
qian
sun
li
zhou
wu
zheng
wang
feng
chen
```
###Output example:
The corresponding output is given here. For example:
```out
chen
feng
li
qian
sun
wang
wu
zhao
zheng
zhou
```







answer:If there is no answer, please comment
The requirements are as follows:
Use string data to receive 10 strings input by keyboard
Write function s that can sort strings_ sort
Use a pointer to a string array as S_ Sort function arguments, to achieve 10 strings sort
Finally, the sorted string is output
be careful:
1) String correlation header file CString
2) Compare the size of two strings using the StrCmp function. The specific operations are as follows:
StrCmp (string variable 1. C_ Str (), string variable 1. C_ str())
Return 1 -- string variable 1 is greater than string variable 2
Return 0 -- equal to
Return - 1 ----- less than
3) Exchange data in two string variables
Swap (string variable 1, string variable 2);
4) When using the pointer to string data, be careful not to exceed the address range! Save the address if necessary