يكي ببينه اين برنامه چكار ميكنه !

spsgorgan

Active Member
سلام دوستان
عزيزان لطفا اين برنامه رو كه ميزارم رو ببنيد چكار ميكنه ! با پاسكال نوشته شده .
اگر كسي هم تونست اين برنامه رو از ايني كه هست بهينه تر كنه ممنونش ميشم .

کد:
[LEFT]
program city;
uses crt;
type
    term=record
        row,col,terms:integer;
    end;
    location=record
    col:integer;
    row:integer;
    end;
var
   matrix:array[0..20,0..20]of byte;
   terms,terms1:term;
   MatrixTerms,k,i,j:integer;
   MatrixRow,MatrixCol,terma,Maxterms:byte;

procedure search(r,w,z,x:byte;var num:byte);
var
   loc:array[1..8]of location;
   row,col,i:byte;
begin
     loc[1].row:=-1;loc[1].col:=0;
     loc[2].row:=-1;loc[2].col:=1;
     loc[3].row:=0;loc[3].col:=1;
     loc[4].row:=1;loc[4].col:=1;
     loc[5].row:=1;loc[5].col:=0;
     loc[6].row:=1;loc[6].col:=-1;
     loc[7].row:=0;loc[7].col:=-1;
     loc[8].row:=-1;loc[8].col:=-1;
     matrix[r][w]:=x;
     for i:=1 to 8 do
     begin
          row:=r+loc[i].row;
          col:=w+loc[i].col;
          

if(row>=1)and(row<=8)and(col>=1)and(col<=8)and(matrix[r

ow][col]=z)then
          begin
               num:=num+1;
               matrix[row][col]:=x;
               search(row,col,z,x,num);
          end;
     end;

end;

var
   input,output:file of term;m,n:byte;
begin
    textbackground(4);
    textcolor(2);
     clrscr;
     assign(input,'city.in');
     assign(output,'city.out');
     rewrite(output);
     rewrite(input);
    write('Enter number of row:');
     readln(terms.row);
     n:=terms.row;
     write('Enter number of column:');
     readln(terms.col);
     m:=terms.col;
     write('Enter sum of one:');
     readln(terms.terms);
     clrscr;
     textbackground(0);
     textcolor(5);
     write(input,terms);
     k:=terms.terms;
     j:=1;
     for i:=1 to k do
        begin
        while true do
          begin
          gotoxy(2,3+j);
          write('enter a row:');
          read(terms.row);
          gotoxy(20,3+j);
          write('enter a column:');
          readln(terms.col);
          if 

(terms.row<=n)and(terms.col<=m)and(terms.col>0)and(term

s.row>0) then
             begin
             terms.terms:=0;
             j:=j+1;
             break;
             end
          else  begin
                j:=j+1;
                gotoxy(2,3+j);
                write('the number not found...  enter new number.  

');
                j:=j+1;
                end;
           end;
          write(input,terms);
       end;
    close(input);
    clrscr;
    reset(input);
    read(input,terms);
    MatrixRow:=terms.row;
    MatrixCol:=terms.col;
    Matrixterms:=terms.terms;
    for i:=1 to k do
    begin
         read(input,terms);
         matrix[terms.row,terms.col]:=1;
   end;
   close(input);
    Maxterms:=0;
    for i:=1 to MatrixRow do
        for j:=1 to MatrixCol do
            if matrix[i][j]=1 then
            begin
               terma:=0;
               search(i,j,1,2,terma);
               terma:=terma+1;
               if terma>Maxterms then
               begin
                  Maxterms:=terma;
                  terms.row:=i;
                  terms.col:=j;
                  terms.terms:=Maxterms;
               end;
            end;
    write(output,terms);
    search(terms.row,terms.col,2,3,terma);
    for i:=1 to MatrixRow do
        for j:=1 to MatrixCol do
            if matrix[i][j]=3 then
            begin
               terms.row:=i;
               terms.col:=j;
               terms.terms:=0;
               write(output,terms);
            end;
    close(output);
    for i:=1 to MatrixRow do
    begin
        for j:=1 to MatrixCol do
        begin
            if matrix[i][j]=3 then
                 textcolor(19)
                 else
                 if(matrix[i][j]=2)then
                     textcolor(5)
                     else
                     textcolor(2);
            write(' ',char(219));
        end;
        writeln;
        writeln
    end;
    reset(input);
    reset(output);
    textcolor(15);
    writeln;
    writeln('     input              output');
    writeln('-------------------------------------------------');
    read(output,terms);
    read(input,terms1);
    writeln('    ',terms1.row,'  ',terms1.col,'  ',terms1.terms,'       

         ',terms.terms);
while(not eof(input))and(not eof(output))do
   begin
   read(input,terms1);
   read(output,terms);
   writeln('    ',terms1.row,'  ',terms1.col,'                

',terms.row,'  ',terms.col);
   end;
while(not eof(input))do
begin
     read(input,terms1);
     writeln('    ',terms1.row,'  ',terms1.col);
end;
close(input);
close(output);
readkey;
end.

[/LEFT]
 

جدیدترین ارسال ها

بالا