O‘quv – uslubiy majmua




Download 1,49 Mb.
bet173/225
Sana25.11.2023
Hajmi1,49 Mb.
#105226
1   ...   169   170   171   172   173   174   175   176   ...   225
Bog'liq
3 02 Informatika fanini o\'qitish metodikasi(1) (2)

Yechish:
Bu masalani boshqacha talqin qilish ham mumkin: N sonini necha hil takrorlanmaydigan usul bilan qiymati Kdan oshmaydigan qo‘shiluvchilarning yig‘indisi ko‘rinishida tasvirlash mumkin? Bunday usullarning juda ko‘p bo‘lishini tushunish qiyin emas.
Belgilash kiritamiz: S(I) - kenguruning maydonning boshidan I-chi katakkacha yetib borishi mumkin bo‘lgan barcha usullar soni bo‘lsin. Faraz qilamiz, birdan to I gacha bo‘lgan har bir J uchun S(J)ning qiymati ma’lum bo‘lsin. Masala shartiga kora I+1 chi katakka kenguru faqat I, I1,…, I-K kataklardan sakrab o‘ta oladi, ya’ni
S(I+1)= S(I)+S(I-1)+...+S(I-K).
Demak, S(N)ni S(1), S(2),..., S(N-1) qiymatlarni ketma-ketlik hisoblash orqali topiladi. Dasturi quyidagicha:
Program Kenguru;
Uses Crt;
Const nm=1000;
Var
n,k,i,j:Integer;
s:Array[1..nm] of Integer;
Begin
TextColor(Yellow); TextBackGround(Blue); ClrScr;
Write('Maydon o‘lchamini kiriting : '); ReadLn(n); Write('Kenguru nechta katakka sakray oladi: '); ReadLn(k); s[1]:=1;
For i:=2 To k Do s[i]:=s[i-1]*2;
For i:=k+1 To n Do
Begin s[i]:=0;
For j:=i-k To i-1 Do s[i]:=s[i]+s[j]; end;
WriteLn('Kenguru maydonni ',s[n],' usulda bosib o‘tadi'); ReadLn; End.
3. Lotin alifbosida yozilgan N ta so‘zdan iborat ketma-ketlik berilgan. Ketma-ketlikdagi hamma anagrammalarni chop etuvchi dastur tuzing (anagramma - bir-biridan harflarning o‘rni bilan farqlanuvchi so‘zlar). Yechish:
Masalani yechish algoritmi quyidagicha:

  1. Berilgan har bir so‘zning harflari ASCI kodi bo‘yicha o‘sish tartibida saralab olinadi.

  2. Hosil bo‘lgan yangi so‘zlar ichidan bir hillari chop etiladi.

Dasturi quyidagicha:
Programm Anagramma;
Uses Crt;
Const nm=100; Var
n,len,i,j,k:Integer;
suz,anagr,an:Array[1..nm] of String[20];
_suz:String; ch:Char;
L:Array[1..nm] Of Integer; bor:Boolean;
Begin
TextColor(Yellow); TextBackGround(Blue); ClrScr;
Write('So‘zlar sonini kiriting : '); ReadLn(n);
For i:=1 To n Do
Begin
Write(i,'-so‘zni kiriting: '); ReadLn(suz[i]); end; For i:=1 To n Do
Begin _suz:=suz[i]; len:=Length(_suz); For k:=1 To len-1 Do Begin ch:=_suz[k]; For j:=k+1 To len Do
Begin
If _suz[j]Then
Begin ch:=_suz[j]; _suz[j]:=_suz[k]; _suz[k]:=ch; end; end; end; anagr[i]:=_suz; end; WriteLn;
For i:=1 To n-1 Do
Begin
If L[i]<>1 Then
Begin
_suz:=anagr[i]; k:=1; an[k]:=suz[i]; bor:=False;
For j:=i+1 To n Do
Begin
If (_suz=anagr[j]) and (L[j]<>1) Then
Begin Inc(k); an[k]:=suz[j]; L[j]:=1; bor:=True; end; end; If bor Then
Begin
For len:=1 To k Do WriteLn(an[len]);
WriteLn('---------'); end; end; end; ReadLn;
End.
4. A(N,N) butun qiymatli kvadrat massiv berilgan. Uning har bir kvadrat qism massivi
(massivning o‘zi ham qism massiv hisoblanadi) elementlari minimumlarini kamayib borish tartibida “JAD.TXT” fayliga, kvadrat qism massivlari sonini “AA.TXT” fayliga yozuvchi dastur tuzing.

Download 1,49 Mb.
1   ...   169   170   171   172   173   174   175   176   ...   225




Download 1,49 Mb.