张惠妹趁早什么意思:一个PASCAL程序

来源:百度文库 编辑:高校问答 时间:2024/04/30 03:07:56
题目:
蛇行矩阵
Problem
蛇形矩阵是由1开始的自然数依次排列成的一个矩阵上三角形。
Input
本题有多组数据,每组数据由一个正整数N组成。(N不大于100)
Output
对于每一组数据,输出一个N行的蛇形矩阵。两组输出之间不要额外的空行。
矩阵三角中同一行的数字用一个空格分开。行尾不要多余的空格。
Sample Input
5
4
Sample Output
1 3 6 10 15
2 5 9 14
4 8 13
7 12
11
1 3 6 10
2 5 9
4 8
7
我编的程序:
program sjsz;
var a:array[1..100,1..100] of integer;
x:array[0..100] of char;
z,b,c,n,d,e,f,g,m,y:integer;
begin
assign(input,'sjsz.in');reset(input);
assign(output,'sjsz.out');rewrite(output);
z:=0; x[0]:='0'; while x[z]<>' ' do begin z:=z+1;
readln(x[z]); end;
y:=z-1; close(input);reset(input);
m:=0;
repeat m:=m+1;
readln(n);
d:=0;
for b:=1 to n do begin
e:=b+1;
for c:=1 to b do begin
d:=d+1;
e:=e-1;
a[e,c]:=d;
end;
end;
for f:=1 to n do begin
for g:=1 to n+1-f do
if g<n+1-f then
write(a[f,g],' ') else write(a[f,g]);
writeln; end; until m=y;
close(input);close(output);
end.
我每次编译都是成功的,可是就是运行不起,请多多指教,感激不尽!

刚才怎么回答不显示!还告诉已经回答过啦~T*M__D

program BaiduZhidao;

{$APPTYPE CONSOLE}

const
Input: integer = 5;
B: integer = 1;
var
x, y: integer;
a: array[1..100, 1..100] of integer;
sum: integer;
begin
for y := 1 to Input do
begin
if y = 1 then a[1, y] := 0 + y else a[1, y] := a[1, y - 1] + y - 1;
for x := 2 to Input + 2 - y do
begin
a[x, y] := a[x - 1][y] + x;
write(a[x - 1, y]);
if x < Input + 2 - y then write(' ');
end;
if y < Input then writeln('');
end;
end.

按你输出结果分析的

program BaiduZhidao;

{$APPTYPE CONSOLE}

const
Input: integer = 10;
B: integer = 1;
var
x, y: integer;
a: array[1..100, 1..100] of integer;
sum: integer;
begin
for y := 1 to Input do
begin
if y = 1 then a[1, y] := 0 + y else a[1, y] := a[1, y - 1] + y - 1;
for x := 2 to Input + 2 - y do
begin
a[x, y] := a[x - 1][y] + x;
write(a[x - 1, y]);
if x < Input + 2 - y then write(' ');
end;
if y < Input then writeln('');
end;
end.

不知道是不是这样输出的,我是按你的输出结果计算的,但是你的描述我实在没太理解!祝好运