Parašė ozzWANTED· 2010 Sau. 13 18:01:52
#5
Vo radau kompe savo senutėlę 1-am kurse rašytą programėlę pascal'iu.
Pakopinsiu jos dalį - vieną iš procedūrų. Joje yra viskas ko tau reikia(ir nereikia :D):
{****** [PRADZIA]: ATMINITES MASYVO Rem_aibe bazes keitimo algoritimas skirtas naujai baziu sumai paskaiciuoti ******}
procedure keisti_baze(var rem_aibe: Masyvas; blevel,n : longint; operaciju_skaicius : longint);
var max_limit,keiciama_baze,einamoji_baze : longint;
begin
max_limit := n-1;
einamoji_baze := blevel;
{***************************** TESTO PRADZIA ********************************}
{***} if(TEST_MODE >= 2)
{***} then Writeln(' Ein. baze: ', einamoji_baze, '; Rem_aibe[',einamoji_baze,']: ', rem_aibe[einamoji_baze], '; Bazes riba: ', max_limit);
{***************************** TESTO PABAIGA ********************************}
while(rem_aibe[einamoji_baze] = max_limit) do // jei pirmas narys yra max. galimas, tai jau lygio o ne bazes keitimas, todel pirma atmetam
begin
{***************************** TESTO PRADZIA ********************************}
{***} if(TEST_MODE >= 2)
{***} then Writeln(' :: 1-oji keiciama baze: ', einamoji_baze, ', Bazes maks. riba: ', max_limit);
{***************************** TESTO PABAIGA ********************************}
if(einamoji_baze = 1)
then break;
max_limit := max_limit-1;
einamoji_baze := einamoji_baze-1;
end;
keiciama_baze := einamoji_baze;
{***************************** TESTO PRADZIA ********************************}
{***} if(TEST_MODE >= 1)
{***} then if(keiciama_baze = blevel)
{***} then Writeln(' Keiciama baze: ties ', keiciama_baze)
{***} else Writeln(' Keiciamos bazes: nuo ', keiciama_baze,' iki ', blevel);
{***************************** TESTO PABAIGA ********************************}
for einamoji_baze:=keiciama_baze to blevel do
begin
if(einamoji_baze = keiciama_baze)
then if(rem_aibe[1] = max_limit)
then rem_aibe[1] := 1
else rem_aibe[einamoji_baze] := rem_aibe[einamoji_baze]+1
else rem_aibe[einamoji_baze] := rem_aibe[einamoji_baze-1]+1;
end;
{***************************** TESTO PRADZIA ********************************}
{***} if(TEST_MODE >= 2)
{***} then begin
{***} Write(' rem_aibe(pr. ',operaciju_skaicius+1,' oper.): ');
{***} for einamoji_baze:=1 to blevel do
{***} Write('[B',einamoji_baze,']: ',rem_aibe[einamoji_baze],', ');
{***} end;
{***************************** TESTO PABAIGA ********************************}
end;
{****** [PABAIGA]: ATMINTIES MASYVO lygio keitimo algoritmo [PABAIGA] ******}
Redagavo ozzWANTED· 2010 Sau. 13 18:01:16