## Russian Determinant

Write here if you have problems with your Pascal source code

Moderator: Board moderators

### Russian Determinant

My task is "Integral Determinant". My number is 684.

I send my program but I have " complier error" . Why??? I have done all as said at "How to submit Pascal programs"… and have a compile error. I know that my program is work … may be not effectively… but it's work … and I confirm it's correctly counting determinants of all matrixes…

So if my program will not accepted I will have been banished from University .. if it will have been happened I will have only one way … way to Russian Army… way to Hell where I have finished my days..

May be I wrong and it's not correctly counting determinants … so show me the way how to make it correctly …. If you know how to dispose from this stupid error .. so show me how I can do it… if you won't people see your comments or program's code… send me to mail pushoc@freemail.ru
I put down my program below..

You know that in the web we exist without skin color, without nationality, without religious bias.. why you should not help me if you can ??? I'm just one alone person living in 9 billion's world. Is there somebody who help me and don't turn his back .. Believe me my life in your hands…

Sincerely Den.

program PXXX(input, output); { ISO states this line in this way }
{\$IFNDEF ONLINE_JUDGE}
{\$M 65500, 0 , 400000}
{\$ENDIF}

const size=30; {The size of the matrix}
type Matrix=array[1..size,1..size] of integer;

var n:integer;
A:Matrix;

{//////////////////////////////////////////////////////
Input a matrix
//////////////////////////////////////////////////////}

function cut_number(search:string;var k:integer):integer;
var j,abba,Code:integer;
str:string;
begin

j:=1;

while search[k]=' ' do k:=k+1;
while (search[k]<>' ')and(k<>length(search)+1) do
begin
str[j]:=search[k];
j:=j+1;
k:=k+1;
end;

str[0]:=chr(j-1);
Val(str,abba,Code);
cut_number:=abba;

end;

var s:string;
j,k:integer;

begin
k:=1;
for j:=1 to n
do A[i,j]:=cut_number(s,k);
end;

var s:string;
k:integer;
i:integer;
begin

k:=1;
n:=cut_number(s,k);

if n=0 then exit;

for i:=1 to n do
begin
end;

end;

{//////////////////////////////////////////////////////
Calculating the determinant of the matrix
///////////////////////////////////////////////////////}

{Function of stopping a processing}

Function finish(A:Matrix;n:integer):boolean;
var i,sum:integer;

begin

sum:=0;
for i:=1 to n do
if A[1,i]<>0 then sum:=sum+1;

if (sum=1)or(sum=0) then finish:=true else finish:=false;

end;

{Exchange the rows}

procedure Exchange(x,y:integer; var A:Matrix;n:integer);
var i,buffer:integer;
begin

for i:=1 to n do
begin

buffer:=A[i,x];
A[i,x]:=A[i,y];
A[i,y]:=buffer;

end;

end;

{Sort the first string of the matrix using buble sort}

Procedure Sort(var A:Matrix;n:integer;var s:integer);
var i,j:integer;
begin
for i:=2 to n do
for j:=n downto i do
if abs(A[1,j-1])>abs(A[1,j]) then
begin
Exchange(j-1,j,A,n);
s:=-s;
end;

end;

{Get sign of a number}

function sign(a:integer):integer;
begin

if a>0 then sign:=1 else
if a=0 then sign:=0 else
if a<0 then sign:=-1;

end;

{Subtract the rows using mathematics rules}

Procedure Subtract(x,y:integer;var A:Matrix;n:integer);
var i:integer;
c:integer;

begin

c:=sign(A[1,y])*sign(A[1,x])*abs(A[1,y] div A[1,x]);

for i:=1 to n do
begin
A[i,y]:=A[i,y]-c*A[i,x] ;
end;

end;

{Process the matrix}

Procedure Processing(var A:Matrix;n:integer);
var i,j:integer;

begin

j:=1;
while(A[1,j]=0)
do j:=j+1;

for i:=j+1 to n do Subtract(j,i,A,n);

end;

{Make current minor from the matrix}

procedure GetMatrix(a:Matrix; var b:Matrix; m,i,j:integer);
var ki,kj,di,dj:integer;
begin
di:=0;
for ki:=1 to m-1 do
begin

if (ki=i) then di:=1;
dj:=0;

for kj:=1 to m-1 do
begin

if (kj=j) then dj:=1;
b[ki,kj]:=a[ki+di,kj+dj];

end;

end;
end;

{Main function}

Function Determinant(a:Matrix;n:integer):integer;
var i,j,d,k,d_sign:integer;
b:Matrix;
begin

{set raw data}
d:=0;
k:=1;
d_sign:=1;

{calculating}

if (n=1) then d:=a[1,1]
else
if (n=2) then d:=a[1,1]*a[2,2]-a[2,1]*a[1,2]
else { n>2 }
begin

while (finish(a,n)=false) do
begin
Sort(A,n,d_sign);
Processing(A,n);
end;

for i:=1 to n do
begin
if a[1,i]<>0 then
begin
GetMatrix(a,b,n,1,i);
d:=d+k*a[1,i]*Determinant(b,n-1);

end;
k:=-k;
end;
end;

{last breath}
Determinant:=d_sign*d;
end;

begin

while not eof(input) do begin
if eoln(input) then begin{ this should follow the while sentence with nothing between, just like this }
readln(input); { skip rest of line }
{writeln(output);} { reproduce the eoln character }
continue; { re-test for EOF }
end;
if n=0 then exit;
writeln(output,Determinant(A,n));

end;

end.
Den
New poster

Posts: 3
Joined: Sun May 04, 2003 11:26 am

Well, I haven't solved this problem yet, but I can give you some hints:

The judge always gives you a reason for a compiler error, so if you read that and follow the hints it gives, you can resolve most of these.
In this case it objects against setting the stringlength by accessing the zeroth element and advises you to use the setlength procedure instead:
change [pascal]str[0]:=chr(j-1);[/pascal]to[pascal]setlength(str,j-1);[/pascal].

Now you've got only Wrong Answer to deal with
One obvious mistake is that you don't print a star after the last line of output. But even correcting this, won't get you Accepted.

As I said, I haven't solved the problem, so this is all the help I can give.

little joey
Guru

Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

little joey thanks alot... may be you are litlle

Thanks.Den.
Den
New poster

Posts: 3
Joined: Sun May 04, 2003 11:26 am