我不知道用什么方法,求方法

1.有N个人的姓名,请把他们按照姓名的字典序排序输出。

样例输入

3

Liying

Wang

Anqian

样例输出

Anqian

Liying

Wang

用字符串函数,strcmp() 字符串比较函数,strcpy()字符串拷贝函数, 供参考:

#include <stdio.h>
#include <string.h>
int main()
{
    char str[20][20],tmp[20];
    int n, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%s", str[i]);

    for (i = 0; i < n - 1; i++) //排序
    {
        for (j = 0; j < n - 1 - i; j++)
            if (strcmp(str[j], str[j + 1]) > 0)
            {
                strcpy(tmp, str[j]);
                strcpy(str[j], str[j + 1]);
                strcpy(str[j + 1], tmp);
            }
    }

    for (i = 0; i < n; i++)  //输出排序后的字符串
        printf("%s\n", str[i]);
    return 0;
}

Ascll是个好东西