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

{$IFDEFNORMAL}{$I-,OBJECTCHECKS-,Q-,R-,S-}{$ENDIFNORMAL}{$IFDEFDEBUG}{$I+,OBJECTCHECK... {$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.
展开
 我来答
bai_lj
2013-05-20 · TA获得超过276个赞
知道小有建树答主
回答量:505
采纳率:77%
帮助的人:277万
展开全部
pascal与C区别很大吗?会pascal,还转不成C?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式