{Andrew Miller

2/11/11

Enloe High School

Lyerly

Contest #2

Int 5}

 

 

{

        ACSLQ2.pas

       

        Copyright 2011 Andrew <lungfishincorporated@gmail.com>

 

            side note: This is ACSL, so I don't comment anything. Sorry.

}

 

Program ACSLQ2;

 

uses crt;

 

var

 

      comma,i,j,searchl,a,q,b:      integer;

    input:                                string;

    search, Str, Stri:              array [1..4] of string[48];

    Len, result:                    array [1..4] of integer;

    sb:                                         array [1..2] of string[1];

 

Begin

 

    clrscr;

 

    write('Input: ');

    readln(input);

    input:=input + ',';

 

    for j:=1 to 4 do

 

      begin

 

            comma:=pos(',', input);

            Str[j]:=copy(input, 1, comma-1);

            Len[j]:=length(Str[j]);

            delete(input, 1, Len[j]+2);

 

        end;

   

    for j:=1 to 4 do result[j]:=0;

 

    for i:=1 to 4 do Stri[i]:=Str[i];

 

for i:=1 to 5 do begin

 

    write('Input: ');

    readln(search[1]);

    search[2]:=search[1];

 

    for j:=1 to 4 do

 

      begin

 

            search[1]:=search[2];

            b:=pos('[', search[1]);

                searchl:=length(search[1]);

                Str[j]:=Stri[j];

 

            if b <> 0 then

 

                  begin

 

                        sb[1]:=copy(search[1], b+1, b+1);

                        sb[2]:=copy(search[1], b+3, b+3);

                        delete(search[1], b, 4);

 

                  end;

 

            if (b = 1) and (Str[j][1] <= sb[2]) and (Str[j][1] >= sb[1]) then

           

                        begin

                       

                              Str[j][1]:=']';

                              search[1][b]:=']';

                             

                        end;

 

            if (b = searchl - 4) and (b <> 0) and (Str[j][Len[j]] <= sb[2]) and (Str[j][Len[j]] >= sb[1]) then

           

                        begin

                       

                              Str[j][Len[j]]:=']';

                              search[1][b]:=']';

                             

                        end;

                       

                a:=pos('*', search[1]);

                searchl:=length(search[1]);

                       

                  {writeln(Str[j]);

            writeln(search[1]);

            writeln('*', a);

            writeln('[', b);

            writeln('?', q);

            writeln;

            readln;}

 

            if a = 1 then delete(search[1], 1, 1);

 

            if a = searchl then

           

                        begin

                       

                              delete(search[1], searchl, 1);                             

                              delete(Str[j], a, 48);

                             

                        end;

                       

                  {writeln(Str[j]);

            writeln(search[1]);

            writeln('*', a);

            writeln('[', b);

            writeln('?', q);

            writeln;

            readln;}

                       

                  q:=pos('?', search[1]);

                 

                  if q <> 0 then delete(search[1], q, 1);

                       

                  result[j]:=pos(search[1], Str[j]);

                 

                  if a = 1 then delete(Str[j], 1, result[j] - 1);

                  delete(Str[j], q, 1);

                 

                  if search[1] = Str[j] then result[j]:=1 else result[j]:=0;

 

            {writeln(Str[j]);

            writeln(search[1]);

            writeln('*', a);

            writeln('[', b);

            writeln('?', q);

            writeln;}

 

        end;

       

    if search[2] = '*?' then for j:=1 to 4 do result[j]:=1;

 

    for j:=1 to 4 do if result[j] = 1 then write(Stri[j], ', ');

 

    if (result[1] = 0) and (result[2] = 0) and (result[3] = 0) and (result[4] = 0) then writeln('No Match')

      else writeln(#8, #8, ' ');

 

end;

 

readln;

 

End.