DropsBrowse Pastes
Login with GitHub

4-2

March 2nd, 2022Views: 14(0 unique)C
#include <stdio.h>
#include <string.h>

char strs[32][16];

void fun(int);

int main(void)
{
    int len;
    scanf("%d", &len);
    for (int i = 0; i < len; i++)
    {
        scanf("%s", strs[i]);
    }
    fun(len);
    for (int i = 0; i < len; i++)
    {
        printf("%s ", strs[i]);
    }
    putchar('\n');
    return 0;
}

void fun(int len)
{
    for (int i = 0; i < len - 1; i++)
    {
        for (int j = 0; j < len - 1 - i; j++)
        {
            if (strcmp(strs[j], strs[j + 1]) > 0)
            {
                char tmp[16] = "";
                strcpy(tmp, strs[j]);
                strcpy(strs[j], strs[j + 1]);
                strcpy(strs[j + 1], tmp);
            }
        }
    }
    return;
}