Baklava Ordusu
Decapat
Daha fazla
- Cinsiyet
- Erkek
Burada kendı yaptığım bir şey var. Çalışıyor çalışmasına, ama 10000 sayısını yazdığımda 10 saniye falan bekletiyor. Bunu daha da hızlandırabilir miyiz? Mesela 1 milyar bile yazsak sonuç 1 dakikanın altında çıksın.
Okul için bir şey.
Okul için bir şey.
Kod:
program RombBirzat;
uses.
sysutils;
var.
n,i: int64;
row: string;
buffer: array of string;
bufferIndex: integer;
outputFile: TextFile;
procedure WriteRow(leadingSpaces, numbers: integer);
var.
num: integer;
begin.
row := StringOfChar(' ', leadingSpaces * 2);
for num := 1 to numbers do.
begin.
if num < 10 then.
row := row + ' ' + IntToStr(num)
else.
row := row + ' ' + IntToStr(num);
end;
buffer[bufferIndex] := row;
Inc(bufferIndex);
end;
procedure FlushBuffer;
var.
i: integer;
begin.
for i := 0 to bufferIndex - 1 do.
writeln(outputFile, buffer[i]);
bufferIndex := 0;
end;
begin.
write('Matrisanyn meydanyny giriz: ');
readln(n);
writeln;
Assign(outputFile, 'diamond_output.txt');
Rewrite(outputFile);
SetLength(buffer, n);
bufferIndex := 0;
for i := 1 to n do.
begin.
if odd(i) then.
WriteRow(n - i, i);
end;
FlushBuffer;
for i := n - 2 downto 1 do.
begin.
if odd(i) then.
WriteRow(n - i, i);
end;
FlushBuffer;
// Close the file.
Close(outputFile);
writeln('Output written to diamond_output.txt');
end.
Son düzenleme: