Module: Subroutines: procedures and functions - 1


Problem

7/12

Shorten program code

Problem

Rabbit Clover continues to learn programming. He has already studied the lines. Recently, he moved on to the study of subroutines, namely procedures. But he doesn't understand how to use them. Recently, Clover wanted to write a program that would print the longest words out of two sentences in a column (if there are several such words, then it would take the first one it encountered). He completely forgot about the procedures and wrote a very complex program.
Here she is:
var max, n: integer;
s1, s2, wordMax, word:string;

begin
    readln(s1);
    readln(s2);
    max := 0;
    s1 := s1 + ' ';
    while length(s1) > 0 to begin
        n := pos(' ', s1);
        word := copy(s1, 1, n);
        if length(word) > max then begin
            max := length(word);
            wordMax := word;
        end;
        delete(s1, 1, n);
    end;
    writeln(wordMax);
    
    max := 0;
    s2 := s2 + ' ';
    while length(s2) > 0 to begin
        n := pos(' ', s2);
        word := copy(s2, 1, n);
        if length(word) > max then begin
            max := length(word);
            wordMax := word;
        end;
        delete(s2, 1, n);
    end;
    writeln(wordMax);
end.
Agree, this is a rather difficult program to understand. 
Help Clover the Rabbit to improve the program by selecting the same actions in the procedure.