SPOON : Getting wa

I published this code few moments ago and it’s giving me incredible headache :smiley:

    program spoon;
var
t,r,c,i,j,k:integer;
matrix:array[1..100,1..100] of char;
found:boolean;
begin
readln(t);
for k:=1 to t do
  begin
  readln(r,c);
  for i:=1 to r do
    begin
      for j:=1 to c-1 do
        begin
        read(matrix[i,j]);
        matrix[i,j]:=LowerCase(matrix[i,j]);
        end;
    readln(matrix[i,c]);
    matrix[i,c]:=LowerCase(matrix[i,c]);
    end;
  if c>=5 then
    for i:=1 to r do
      begin
      found:=false;
      for j:=1 to (c-4) do
        if matrix[i,j]='s' then
          if matrix[i,j+1]='p' then
            if matrix[i,j+2]='o' then
              if matrix[i,j+3]='o' then
                if matrix[i,j+4]='n' then
                  begin
                  found:=true;
                  break;
                  end;
      if found then break;
      end;
  if found then writeln('There is a spoon!')
    else
    begin
    if r>=5 then
      for i:=1 to c do
        begin
        found:=false;
        for j:=1 to r-4 do
          if matrix[j,i]='s' then
            if matrix[j+1,i]='p' then
              if matrix[j+2,i]='o' then
                if matrix[j+3,i]='o' then
                  if matrix[j+4,i]='n' then
                    begin found:=true; break; end;
        if found then break;
        end;
    if found then writeln('There is a spoon!')
      else
      Writeln('There is indeed no spoon!');
   end;
  end;
end.

This is what I’ve put and it’s giving me wrong answer.
There is no way this could be wrong answer I’m 100% sure about it. Could someone help me with this?
Thanks in advance…

“There is no way this could be wrong answer I’m 100% sure about it.”

come on … :slight_smile:

2
1 5
spoon
1 1
a

could you please give us the output of your program for that input test file ?

2 Likes

For the first test example it gives me There is a spoon, but for the second one it’s wrong - also gives me There is a spoon. Believe it or not, I’m wrong :smiley: Thank you for this info, I’m going to correct my code :smiley:

program spoon;
var
t,r,c,i,j,k:integer;
matrix:array[1…100,1…100] of char;
found:boolean;
begin
readln(t);
for k:=1 to t do
begin
readln(r,c);
for i:=1 to r do
begin
for j:=1 to c-1 do
begin
read(matrix[i,j]);
matrix[i,j]:=LowerCase(matrix[i,j]);
end;
readln(matrix[i,c]);
matrix[i,c]:=LowerCase(matrix[i,c]);
end;

if (r<5) and (c<5) then begin writeln(‘There is indeed no spoon!’);continue;
end;

if c>=5 then
    for i:=1 to r do
      begin
      found:=false;
      for j:=1 to (c-4) do
        if matrix[i,j]='s' then
          if matrix[i,j+1]='p' then
            if matrix[i,j+2]='o' then
              if matrix[i,j+3]='o' then
                if matrix[i,j+4]='n' then
                  begin
                  found:=true;
                  break;
                  end;
      if found then break;
      end;
  if found then writeln('There is a spoon!')
    else
    begin
    if r>=5 then
      for i:=1 to c do
        begin
        found:=false;
        for j:=1 to r-4 do
          if matrix[j,i]='s' then
            if matrix[j+1,i]='p' then
              if matrix[j+2,i]='o' then
                if matrix[j+3,i]='o' then
                  if matrix[j+4,i]='n' then
                    begin found:=true; break; end;
        if found then break;
        end;
     if found then writeln('There is a spoon!')
      else
      Writeln('There is indeed no spoon!');
   end;
  end;
end.

I’ve corrected the code and it still gives me Wrong answer. Could you give me more test examples to check my app (corrected piece of code is marked in bold italic).
You wouldn’t believe how much I wanted to throw computer through the window when I saw wrong answer :smiley:
Thanks :slight_smile:

same mistake. you corrected it half-way.

2
1 5
spoon
5 1
a
a
a
a
a

be very careful with your found var… it never resets properly.

oh, and try that one, you’ll understand something else :

1
5 1
s
p
o
o
n

good luck.

2 Likes

Thank you very much, I figured that I was stupid enough not to reset found boolean :smiley: Only one line of code was what I missed :smiley:

1 Like
//