so - this is not direct reply for problem in the first post of thread - but - my usual request for help!!!
So - here is my code - array pieces[...] contain the words to be exchanged by numbers in encryption/decription. No special collection (e.g. very nice Classes.TStringList) is used as Judge gives compile error in such a case.
My code give the same result for test case - but judge gives WA. I have some thought that it mau be related that judge may handle carriage return/line feed for newlines differently than my WinXP/Delphi6 on which I am developing and testing.
Thanks a lot for any hint or advice in advance!!! Especially - it could be so great if someone coudl provide some tests cases against which my program fails to five the correct answer!!!
Code: Select all
program Prg2450(input, output);
{$APPTYPE CONSOLE}
//uses Classes;
var ch: char;
piece: String;
number: String;
intNumber: SmallInt;
errorCode: Cardinal;
posPiece,posNumber: Cardinal;
inPiece,inNumber: boolean;
chCode: integer;
pieces: array[0..1000000] of String;
positions: array[0..1000000] of Integer;
currentPieceNo: Integer;
currentPosition: Integer;
i: Integer;
inNewLine: Boolean;
ch13: char;
//strList: TStringList;
begin
{
AssignFile(Input, 'in02__.txt');
Reset(Input);
AssignFile(Output, 'out02__.txt');
Rewrite(Output);
}
setLength(piece,50);
setLength(number,50);
currentPieceNo:=1;
inPiece:=false;
inNumber:=false;
posPiece:=1;
posNumber:=1;
while not Eof(input) do
begin
if Eoln(input) then begin
// begin
if inPiece then begin
for i:=currentPieceNo downto 2 do begin
positions[i]:=positions[i-1];
end;
write(copy(piece,1,posPiece-1));
pieces[currentPieceNo]:=copy(piece,1,posPiece-1);
positions[1]:=currentPieceNo;
currentPieceNo:=currentPieceNo+1;
inPiece:=false;
posPiece:=1;
end;
if inNumber then begin
val(copy(number,1,posNumber-1),intNumber,errorCode);
write(pieces[positions[intNumber]]);
currentPosition:=positions[intNumber];
for i:=intNumber downto 2 do begin
positions[i]:=positions[i-1];
end;
positions[1]:=currentPosition;
inNumber:=false;
posNumber:=1;
end;
// end
ReadLn(input);
Read(input,ch);
chCode:=LongInt(ch);
//output together with tests - end or not to end
if chCode=48 then exit;
if chCode=13 then begin
ch13:=ch;
read(ch);
chCode:=LongInt(ch);
if chCode=48
then exit
else begin
writeln(output);
write(ch13);
end;
end else begin
writeln(output);
end;
end else begin
Read(input, ch);
chCode:=LongInt(ch);
end;
case chCode of
0..31,32,33..47, 58..64, 91..96, 125..255:
begin
if inPiece then begin
for i:=currentPieceNo downto 2 do begin
positions[i]:=positions[i-1];
end; //???
write(copy(piece,1,posPiece-1));
pieces[currentPieceNo]:=copy(piece,1,posPiece-1);
positions[1]:=currentPieceNo;
currentPieceNo:=currentPieceNo+1;
inPiece:=false;
posPiece:=1;
end;
if inNumber then begin
val(copy(number,1,posNumber-1),intNumber,errorCode);
// let 0-lth element is left unused
write(pieces[positions[intNumber]]);
currentPosition:=positions[intNumber];
// moving the current word to the front of list
for i:=intNumber downto 2 do begin
positions[i]:=positions[i-1];
end;
positions[1]:=currentPosition;
inNumber:=false;
posNumber:=1;
end;
if (chCode<>10)
then write(ch)
else writeLn(output);
end;
48..57:
begin
if ((not inNumber) and (chCode=48)) then exit;
number[posNumber]:=ch;
posNumber:=posNumber+1;
inNumber:=true
end;
else
begin
piece[posPiece]:=ch;
posPiece:=posPiece+1;
inPiece:=true
end;
end; // case
end; // while
end.