一个pascal程序,求转 c/c++,c#,java,VB,javascript,php,等等的计算机语言

{$IFDEF NORMAL}
{$I-,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF NORMAL}
{$IFDEF DEBUG}
{$I+,OBJECTCHECKS-,Q+,R+,S-}
{$ENDIF DEBUG}
{$IFDEF RELEASE}
{$I-,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF RELEASE}

program n_dice_distribution;

uses crt;
const max_dice = 6; //max dice number
max_n = 10; //max throwing dices times

f_max_size = max_dice * max_n; //max size of f

tab_sp = 10; //tab spaces

//put_text = 0;

var f:array[1..f_max_size]of longint;
i,j,k:longint;
n:longint;
ch:char;
fin:boolean;

procedure n_dice(m:longint; sum:longint);
var i:longint;
begin
if(m=n)then begin
inc(f[sum]);
end else begin
for i:=1 to max_dice do begin
n_dice(m+1,sum+i);
// after throwed the (m+1)th time, add i to the sum
end;
end;
end;

procedure print_res;
begin
writeln('n=', n:tab_sp-2);

write('sum: ');
for i:=1 to max_dice * n do write( i:tab_sp,' '); writeln;
write('distrib: ');
for i:=1 to max_dice * n do write(f[i]:tab_sp,' '); writeln;

for i:=1 to max_dice * n -1 do
if(f[i]<>0)and(f[i]>=f[i+1])then begin

if(f[i]>f[i+1]) then
write('max_psu= ',i:tab_sp)
else
write('max_psu= ',i:tab_sp,' ',i+1:tab_sp); writeln;

write('max_pst= ',f[i]:tab_sp); writeln;
write('thr_tme= ',trunc(exp(n * ln(max_dice) )) :tab_sp ); writeln;
write('max_pty= ',f[i]/ exp(n * ln(max_dice) ) :tab_sp:5); writeln;

break;
end;

writeln;
end;

begin
clrscr;
assign(input,'f:\n_dice\in.txt');
assign(output,'f:\n_dice\out.txt');
reset(input); rewrite(output);

fin:=false;

while( not fin )do begin

fillchar(f, sizeof(f) , 0);

{
write('input n: ');
}

readln(n);

if(n<=0) then begin
writeln('invalid : n = ',n:tab_sp);
halt;
end;

n_dice(0,0);
// after throwed the 0th time, get the sum = 0

print_res;

{
write('finished? (y/n): ');
ch:= readkey;
}

fin:=( eof(input)or(ch='y')or(ch='Y') );
if(fin)then break;
writeln;

end;

close(input); close(output);

end.

第1个回答  2013-05-20
pascal与C区别很大吗?会pascal,还转不成C?
相似回答
大家正在搜