input : a sentance between 1 to 10.000 char. every word on the sentance include 1 to 200 char 'a' to 'z'.
output : word which is a palindrome

Example :
Input

apa yang di alami malam ini oleh anna dan saras tidak pernah ada

Output

apa malam ini anna saras ada

here is my program but when i submit it, only got 20 points. any idea which testcase will make it wrong answer ?

program kodok_goreng;
function cek(a : string) : boolean;
var
k : integer;
b : string;
temp : char;
begin
     b := a;
     for k := 1 to length(a) div 2 do
     begin
          temp := a[k];
          a[k] := a[length(a)+1-k];
          a[length(a)+1-k] := temp;
     end;
     if a = b then cek := true
     else cek := false;


end;

var
   a : array[1..10000] of char;
   b : array[1..10000] of string;
   c : array[1..10000] of string;
   k,l,m,s : integer;
   q : string;
begin
     k := 0;
     s := 0;
     while not eof(input) do
     begin
          k := k + 1;
          read(a[k]);
          if a[k] = ' ' then
          begin
               s := s+1;
               q := '                                                                                                                                                                                                       ';
               for l := 1 to k do
               begin
                    q[l] := a[l];
               end;
               b[s] := q;
               k := 0;
          end;
     end;
               s := s+1;
               q := '                                                                                                                                                                                                       ';
               for l := 1 to k do
               begin
                    q[l] := a[l];
               end;
               b[s] := q;

     for l := 1 to s do
     begin
          q := b[l];
          for m := length(q) downto 1 do
          begin
               if q[m] = ' ' then delete(q,m,1);
          end;
          //writeln(q);
          b[l] := q;
     end;
     k := 0;
     for l := 1 to s do
     begin
          if cek(b[l]) then
          begin
               k := k + 1;
               c[k] := b[l];
          end;
     end;
     for l := 1 to k do
     begin
          write(c[l]);
          if l <> k then write(' ');
     end;
     writeln;
end.

It could be that you did not need two 10000 string arrays. A single string could be used for capturing the output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.