#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#define N 1000
#define M 1000
int main()
{
    char arr[1000][M] = { 0 };
    char str[N], result[N];
    char sp[] = " ";
    //Удалил переменную tmp и все что с ней связано, т.к. бесполезная
    int count = 0, max = 0, maxI = 0;

    fgets(str, N - 1, stdin);

    char* token = strtok(str, sp);
    int i = 0;
    while (token != NULL)
    {
        count = strlen(token);
        //Тут я думаю логичней использовать strcpy а не strcat
        strcpy(arr[i], token);
       
        if (count > max) {
            max = count;
            maxI = i;
        }

        ++i;
        token = strtok(NULL, sp);
    }

    char tmp_str[M];
    strcpy(tmp_str, arr[0]);
    strcpy(arr[0], arr[maxI]);
    strcpy(arr[maxI], tmp_str);

    for (int j = 0; j < i; j++)
        printf("%s%s", arr[j], j < i - 1 ? " " : "");

    return 0;
}