langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,40 @@
Program GreatestSubsequentialSum(output);
var
a: array[1..11] of integer = (-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1);
i, j: integer;
seqStart, seqEnd: integer;
maxSum, seqSum: integer;
begin
maxSum := 0;
seqStart := 0;
seqEnd := -1;
for i := low(a) to high(a) do
begin
seqSum := 0;
for j := i to high(a) do
begin
seqSum := seqSum + a[j];
if seqSum > maxSum then
begin
maxSum := seqSum;
seqStart := i;
seqEnd := j;
end;
end;
end;
writeln ('Sequence: ');
for i := low(a) to high(a) do
write (a[i]:3);
writeln;
writeln ('Subsequence with greatest sum: ');
for i := low(a) to seqStart - 1 do
write (' ':3);
for i := seqStart to seqEnd do
write (a[i]:3);
writeln;
writeln ('Sum:');
writeln (maxSum);
end.