主题:tju1008
fxzxg
[专家分:430] 发布于 2005-10-03 21:17:00
program tju1008;
var yh:array[1..35,1..35] of integer;
i,j,max,k,m,x:integer;
n:array[1..10] of integer;
begin
while not seekeof(input) do
begin
max:=0;
k:=0;
fillchar(n,sizeof(n),0);
while not seekeoln(input) do
begin
k:=k+1;
read(n[K]);
if n[k]>max
then max:=n[k];
end;
yh[1,1]:=1;
for i:=2 to max do
begin
yh[i,1]:=1;
yh[i,i]:=1;
for j:=2 to i-1 do
yh[i,j]:=yh[i-1,j-1]+yh[i-1,j];
end;
max:=k;
k:=0;
for m:=1 to max do
begin
x:=x+1;
k:=k+1;
writeln('Case ',x,':');
for i:=1 to n[k] do
begin
for j:=1 to i do
begin
write(yh[i,j]);
if j<>i
then write(' ');
end;
writeln;
end;
end;
end;
end.
又是超时~~~~~~~~~~~
回复列表 (共4个回复)
沙发
林记 [专家分:1680] 发布于 2005-10-03 21:21:00
扬辉三角....怎么可能会超时
不用每次读入都重算吧
板凳
fxzxg [专家分:430] 发布于 2005-10-03 22:13:00
program tju1008;
var yh:array[1..35,1..35] of integer;
i,j,max,k,m,x:integer;
n:array[1..10] of integer;
f:boolean;
begin
while not seekeof(input) do
begin
max:=0;
k:=0;
f:=false;
fillchar(n,sizeof(n),0);
while not seekeoln(input) do
begin
k:=k+1;
read(n[K]);
if n[k]>max
then begin
max:=n[k];
f:=true;
end;
end;
if f then begin
yh[1,1]:=1;
for i:=2 to max do
begin
yh[i,1]:=1;
yh[i,i]:=1;
for j:=2 to i-1 do
yh[i,j]:=yh[i-1,j-1]+yh[i-1,j];
end;
end;
max:=k;
k:=0;
for m:=1 to max do
begin
x:=x+1;
k:=k+1;
writeln('Case ',x,':');
for i:=1 to n[k] do
begin
for j:=1 to i do
begin
write(yh[i,j]);
if j<>i
then write(' ');
end;
writeln;
end;
end;
end;
end.
还是不过!!!!!!!!!!!!!
3 楼
林记 [专家分:1680] 发布于 2005-10-03 22:55:00
program tju1008;
var yh:array[1..35,1..35] of longint;
i,j,lmax,max,m,x,n:integer;
begin
yh[1,1]:=1;
max:=1;
lmax:=1;
x:=0;
m:=0;
while not seekeof(input) do
begin
readln(n);
if n>max then
begin
lmax:=max;
max:=n;
end;
for i:=lmax to max do
begin
yh[i,1]:=1;
yh[i,i]:=1;
for j:=2 to i-1 do
yh[i,j]:=yh[i-1,j-1]+yh[i-1,j];
end;
x:=x+1;
if m<>0 then writeln;
m:=1;
writeln('Case ',x,':');
for i:=1 to n do
begin
for j:=1 to i do
begin
write(yh[i,j]);
if j<>i
then write(' ');
end;
writeln;
end;
end;
end.
你的程序问题也太多了吧,我改你的程序比自己重新编还要辛苦~~~
4 楼
eboy01 [专家分:160] 发布于 2005-10-03 23:18:00
program yanghui;
var
a:array[1..34,1..34] of longint;
n,i,o,p:longint;
begin
p:=0;
while not seekeof(input) do
begin
p:=p+1;
readln(n);
if p<>1 then writeln;
for i:=1 to n do
a[i,1]:=1;
for i:=2 to n do
for o:=2 to i do
a[i,o]:=a[i-1,o]+a[i-1,o-1];
writeln('Case ',p,':');
for i:=1 to n do
for o:=1 to i do
begin
if o<>i then write(a[i,o],' ')
else begin write(a[i,o]);writeln;end;
end;
end;
end.
我来回复