(* Generazione input per "Il castello" (IOI 1994) Copyright (C) 2000 Paolo Boldi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) program Gen9412(input,output); (* Converte un file di input della forma ############# # | | # # | # ###---#---### ... in un file di output nel formato corretto. Nel file di input, ogni cella ha la seguente forma ### # # ### dove il # pu• essere sostituito da un | o un - per indicare l'assenza di muro (NOTA: le quattro celle d'angolo non contano) *) var inputfile,outputfile: string; (* Nome dei file *) dati: array [1..50*2+1] of string; r,c: byte; (* Righe/colonne *) procedure inp; var f: text; i,j: byte; begin assign(f,inputfile); reset(f); i:=0; while (not eof(f)) do begin inc(i); readln(f,dati[i]); if (i>1) and (length(dati[i])<>length(dati[i-1])) then begin writeln('Errore lunghezza alla riga ',i); halt(1) end; end; r:=(i-1) div 2; c:=(length(dati[i])-1) div 2; close(f) end; procedure out; var f: text; ir,ic,v: byte; begin assign(f,outputfile); rewrite(f); writeln(f,r); writeln(f,c); for ir:=1 to r do begin for ic:=1 to c do begin v:=0; if (dati[2*ir-1,2*ic]='#') then v:=v+2; if (dati[2*ir+1,2*ic]='#') then v:=v+8; if (dati[2*ir,2*ic+1]='#') then v:=v+4; if (dati[2*ir,2*ic-1]='#') then v:=v+1; write(f,v,' ') end; writeln(f) end; close(f) end; begin write('Nome file di input: '); readln(inputfile); write('Nome file di output: '); readln(outputfile); inp; out end.