I published this code few moments ago and it’s giving me incredible headache
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…
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 Thank you for this info, I’m going to correct my code
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
Thanks