Ikkinchi darajali tub son


Download 0.69 Mb.
Sana24.10.2020
Hajmi0.69 Mb.
#136249
Bog'liq
Olimpiyada masalalari javobi bilan





  1. Ikkinchi darajali tub son. Agar tub sonning teskari tartibdagi soni xam tub bo`lsa u 2- darajali tub son deyiladi. Berilgan sonni 2- darajali tub yoki tub emasligini aniqlovchi dastur tuzing.

Kiruvchi ma`lumotlar: N( 10
CHikuvchi ma`lumotlar : Agar 2- darajali tub son bo`lsa “ Yes “ , aks xolida “ No” ni chiqaring.
Program ikkinchi_darajali_tub;

Uses crt;

LABEL 1,2;

Var I,J,N,S,k,t,len,c: integer;

a,b,d: string;

begin


clrscr; s:=0;

write(' n sonini kiriting ');readln(n);

for i:=1 to n do

begin


if n mod i=0 then s:=s+1;

end;


if s=2 then k:=1;

if k=1 then str(n,a);

len:=length(a);

for j:=1 to len do

begin

b:=copy(a,j,1);



d:=b+d;

end;


val(d,t,c); s:=0;

for i:=1 to t do

begin

if t mod i=0 then s:=s+1;



end;

if s=2 then write(n,' ',t,' yes');

if s<>2 then writeln(' no');

end.




  1. Antipolndrom . Polindrom satr deb simmetrik satrga aytiladi. Yani ushbu satrni teskari tartibi uning o`zi bilan bir xil.Berilgan satrdan polindrom bo`lmagan eng uzun satr bo`lagini topuvchi dastur tuzish kerak.

Kiruvchi ma`lumot: 100000 belgidan oshmagan S satr.

CHikuvchi ma`lumot : Masalaga mos javobni chiqaring. Agar satrda polindrom bo`lmagan qism mavjud bo`lmasa NO SOLUTION chiqaring.
program Antipolindrom;

uses crt;

label 1;

var i,k: integer; n,m,s: string;

begin

write(' n sonini kiriting ');readln(n);



k:=length(n);

write(n);

writeln; writeln;

for i:=1 to k do

begin

m:=copy(n,i,1); s:=m+s;



end;

if n<>s then begin writeln(n); goto 1;end;

if n=s then begin delete(n,k,1); writeln(n); goto 1;end;

delete(n,k-2,2);delete(s,k-2,2);

if n=s then writeln(' no solution ');

1: end.



  1. Teskari tartib. Berilgan ketma-ketlikni teskarisiga chiqarib beruvchi dastur tuzing.Dasturda massiv ishlatish mumkin emas.

Kiruvchi ma`lumotlar: Birinchi katorda natural N (N<=100) soni.keyingi katorda N

ta butun son .Sonlar modul jixatidan 1000 dan oshmaydi.



CHikuvchi mz`lumotlar : Berilgan ketma ketlikni teskari tartibda chiqaring.
program teskari_tartib;

uses crt;

var i,k: integer; n,m,s: string;

begin


write(' n sonini kiriting ');readln(n);

k:=length(n);

write(n);

writeln; writeln;

for i:=1 to k do

begin


m:=copy(n,i,1); s:=m+s;

end;


writeln(s);

end.

4.Uchburchak va nukta,Учбурчак ўзининг (x1,y1), (x2,y2), (x3,y3) учларининг координаталари ва нукта (x,y) координатаси билан берилган. Берилган нултанинг учбурчак ичида ётиши ёки ётмаслигини аникланг.}

program O1; uses crt;

var

x1,y1,x2,y2,x3,y3,z1,z2,t1,t2,x,y:real;



a,s,sa,s1,s2,s3,a1,b1,c1,p,t,b,c:real;

procedure hisob;

begin

s:=sqrt(sqr(z1-z2)+sqr(t1-t2));



end;
begin Clrscr;

write('Учбурчак 1-учининг координатаси x1, y1 ни киритинг '); readln(x1,y1);

write('Учбурчак 2-учининг координатаси x2, y2 ни киритинг '); readln(x2,y2);

write('Учбурчак 3-учининг координатаси x3, y3 ни киритинг '); readln(x3,y3);

z1:=x1; t1:=y1; z2:=x2; t2:=y2; hisob; a:=s;

z1:=x2; t1:=y2; z2:=x3; t2:=y3; hisob; b:=s;

z1:=x3; t1:=y3; z2:=x1; t2:=y1; hisob; c:=s;

p:=(a+b+c)/2;

t:=sqrt(p*(p-a)*(p-b)*(p-c)); sa:=t;

write('Нуктанинг координатаси x, y ни киритинг '); readln(x,y);

z1:=x; t1:=y; z2:=x1; t2:=y1; hisob; a1:=s;

z1:=x; t1:=y; z2:=x2; t2:=y2; hisob; c1:=s;

z1:=x; t1:=y; z2:=x3; t2:=y3; hisob; b1:=s;

p:=(a1+c1+a)/2;

t:=sqrt(p*(p-a1)*(p-c1)*(p-a)); s1:=t;

p:=(a1+b1+c)/2;

t:=sqrt(p*(p-a1)*(p-b1)*(p-c)); s2:=t;

p:=(c1+b+b1)/2;

t:=sqrt(p*(p-c1)*(p-b)*(p-b1)); s3:=t;

if (sa = (s1+s2+s3)) then writeln('Нукта учбурчак ичида ётади')

else writeln ('Нукта учбурчак ичида ётмайди');

end.



  1. Qoldiqli bo`lish. Ikkita N va K sonlari berilgan . N ni K ga bo`lgandagi qoldiqni topuvchi dastur tuzing.

Kiruvchi ma`lumotlar: Ikkita butun son N va K (1<=N<= 10100, 1<=K,=109)

CHiquvchi ma`lumotlar : N ni K ga bo`lgandagi qoldiq chiqadi.
program qoldiqli_bolish;

uses crt;

var i,k,n,m: integer;

begin


write(' n ba m sonlarini kiriting ');readln(n,m);

while n>0 do

begin

k:=n - m;



n:=k;

end;


writeln('k= ',k+m);

end.



  1. Dasturchilar kuni xar yilning 255 kuniga to`gri keladi ( bunda 1- yanvar 0 – kun xisoblanadi) Berilgan yildagi dasturchilar kuni qaysi sanaga to`gri kelishini aniqlash dasturi tuzilsin.

Kiruvchi ma`lumotlar: Bitta butun yilni ifodalovchi son.

CHiquvchi ma`lumotlar: Dasturchilar kuni sanasi DD/MM/YYYY DD –sana,MM-oy , YYYY yil .
Program kalendar;

uses crt;

var a,b,c,I,J: integer; M: array[1..11] of integer;

Function D (x: integer): boolean;

Begin

D:=(c mod x)=0;



end;
Begin

write('a,b,c ni kiriting:');Readln(a,b,c);


For I:=1 to 11 do

case i of

1,3,5,7,8: M[i]:=31;

4,6,9,11: M[I]:=30;

2: M[I]:=28;

End;


J:=A;

for I:=1 to b-1 do J:=J+M[I];

If (B>2) And (D(4) and not(D(100)) or D(400)) then J:=J+1;

writeln('Kunar soni ',j-1,' ga teng ', a,'/',b,'/',c);


End.

7. Faqat o`ngga yoki pastga. N*M jadval nomanfiy butun sonlar bilan to`ldirilgan .O`yin koidalari quyidagicha : O`yin 1*1 katakdan boshlanadi va N*M katakda tugashi kerak.Har bir katakdagi sonlar o`ngga yoki pastga yuruvchi qadamlar sonini ifodalaydi .



Kiruvchi ma`lumotlar: Birinchi qatorda jadval o`lchami N (1<=N<=70) va M (1<=M<=70)

Keyingi N ta qatorda M tadan butun nomanfiy sonlar berilgan.



CHikuvchi ma`lumotlar: Yo`llar sonini chiqaring.
Program ong_pastga;

uses crt;

var i,j,k,l,m,n: integer;

a: array [1..3,1..4] of integer;

begin

write(' m va n sonlarini kiriting');readln(m,n);



for i:=1 to n do

begin


for j:=1 to m do

begin


write('a(',i,',',j,')= '); readln(a[i,j]);

end;end;


for i:=1 to n do

begin


k:=0;

for j:=1 to m do

begin

if (a[1,1]=2) and (a[3,1]=3) and (a[3,4]=0) then k:=k+1;



if (a[1,1]=2) and (a[1,3]=1) and (a[2,3]=1) and (a[3,3]=1) and (a[3,4]=0) then k:=k+1;

if (a[1,3]=1) and (a[1,4]=2) and (a[3,4]=0) then k:=k+1;

end;

writeln( ' yollar soni ',k);



end;

end.
8. SHaxmat. Shaxmat doskasi 8*8 o`lchamda bo`lib ok ba kora rangda bo`yalggan. Xar bir kator xarfiy va rakamli adresga ega. Yani gorizantal a dan h gacha vertical 1 dan 8 gacha nomerlangan , agar a1 katak kora rangda ekani ma`lum bo`lsa so`raglan katakni rangini aniqlash dasturi tuzilsin.


program shaxmat;

uses crt;

label 1,2;

var i,j,c: integer;

a,b: array [1..8] of string;

m,a1,a2,a3,a4,a5,a6,a7,a8: string;

b1,b2,b3,b4,b5,b6,b7,b8: string;

c1,c2,c3,c4,c5,c6,c7,c8: string;

d1,d2,d3,d4,d5,d6,d7,d8: string;

e1,e2,e3,e4,e5,e6,e7,e8: string;

f1,f2,f3,f4,f5,f6,f7,f8: string;

g1,g2,g3,g4,g5,g6,g7,g8: string;

h1,h2,h3,h4,h5,h6,h7,h8: string;

begin


write(' kiziktirgan katak adresini kiriting ');readln(m);

if (m='a1') or (m='a3') or (m='a5') or (m='a7') then begin writeln(m,' katak kora rangda'); end;

if (m='a2') or (m='a4') or (m='a6') or (m='a8') then begin writeln(m,' katak ok rangda'); end;

if (m='b1') or (m='b3') or (m='b5') or (m='b7') then begin writeln(m,' katak ok rangda'); end;

if (m='b2') or (m='b4') or (m='b6') or (m='b8') then begin writeln(m,' katak kora rangda'); end;

if (m='c1') or (m='c3') or (m='c5') or (m='c7') then begin writeln(m,' katak kora rangda'); end;

if (m='c2') or (m='c4') or (m='c6') or (m='c8') then begin writeln(m,' katak ok rangda'); end;

if (m='d1') or (m='d3') or (m='d5') or (m='d7') then begin writeln(m,' katak ok rangda'); end;

if (m='d2') or (m='d4') or (m='d6') or (m='d8') then begin writeln(m,' katak kora rangda'); end;

if (m='e1') or (m='e3') or (m='e5') or (m='e7') then begin writeln(m,' katak kora rangda'); end;

if (m='e2') or (m='e4') or (m='e6') or (m='e8') then begin writeln(m,' katak ok rangda'); end;

if (m='f1') or (m='f3') or (m='f5') or (m='f7') then begin writeln(m,' katak ok rangda'); end;

if (m='f2') or (m='f4') or (m='f6') or (m='f8') then begin writeln(m,' katak kora rangda'); end;

if (m='g1') or (m='g3') or (m='g5') or (m='g7') then begin writeln(m,' katak kora rangda'); end;

if (m='g2') or (m='g4') or (m='g6') or (m='g8') then begin writeln(m,' katak ok rangda'); end;

if (m='h1') or (m='h3') or (m='h5') or (m='h7') then begin writeln(m,' katak ok rangda'); end;

if (m='h2') or (m='h4') or (m='h6') or (m='h8') then begin writeln(m,' katak kora rangda'); end;

end.
9. Sonni topish. Shunday eng kichik natural sonni topinki uning raqamlarini ko`paytmasi berilgan N soniga teng bo`lsin


program sonni_topish;

uses crt;

var i,j,k,n,m,c,t: integer;

a,b: string;

begin

write(' N sonini kiriting ');readln(n);



for i:=10 to 100 do

begin


k:=1;

str(i,a); m:=length(a);

for j:=1 to m do

begin


b:=copy(a,j,1); val(b,t,c); k:=k*t;

end;


if k=n then Writeln(i);

end;


end.
10. Ajdarlar.Ertakdagi ajdarlarning boshlari bir nechta bo`lishi ma`lum бгдфктштп kuchi boshlarini soni bilan aniklanadi.Lekin ajdarlar bir nechta bo`lsa ularning kuchi boshlarining sonlarini ko`paytmasiga teng bo`ladi.

Masalan 3 ta ajdar boshlari mos ravishda 3,4,5 ta bo`lsa ularning kuchi 60 ga teng bo`ladi.Sizga ajdarlar boshlarining soni beriladi , sizning vazifangiz ushbu guruxdagi ajdarlar ega bo`lishi mumkin bo`lgan maksimal kuchni topish so`raladi.



Kiruvchi ma`lumotlar : bitta katorda 0< N < 100 beriladi , Ajdarlar boshlarining yigindisi.

N=6 maksimal kuchi 9, N=8 maksimal kuchi 18 , N=13 maksimal kuchi 108


program ajdarlar;

uses crt;

var n,s,j: integer;

i: real;


begin

write(' Ajdarlar boshi sonini kiriting '); readln(n);

repeat

if n mod 3=0 then begin n:=n-3; s:=s+1; end else begin n:=n-2; j:=j+1; end;



until n<=0;

i:=exp(s*ln(3))*exp(j*ln(2));

writeln ( ' ajdarlar maksimal kuchi ',i);

end.


11. Jek va uning imtixonlari. Yilning oxiriga kelib Jekning imtixonlari boshlandi.Jekning imtixonlari N kunda bo`lib o`tadi.bular a[1],a[2],…a[n] ketma-ketlikda imtixonlarning bo`lish ketma-ketligi va u K ta fandan imtixon topshirishi kerak.Fanlar 1 dan K gacha bo`lgan sonlar bilan nomerlangan. N ta kunning xar birida qaysidir bitta fandan imtixon bolishi yoki bo`lmasligi mumkin.Jek sal dangasarok va u xar yili imtixonlar boshlangandan keyngina imtixonlarga tayyorlanishni boshlaydi.u xar J inchi ( 1<= J <= k) fanga b[j] kun tayyorgarlik ko`rishi kerak. Agar b[j] kun tayyorgarlik ko`rmasa u bu imtixondan o`taolmaydi.

Jek bilmokchiki qanday minimal kunda imtixonlarni topshirib bo`ladi.

program imtixon;

uses crt;

var i,j,n,s,k,m: integer;

a,b: array [1..10] of integer;

begin

write(' necha kun ichida imtixon bo`lib o`tadi');readln(n);



write(' nechta fandan imtixon bo`adi');readln(k);

for i:=1 to n do

begin

write('a(',i,')=');readln(a[i]);



end;

for j:=1 to k do

begin

write('b(',j,')=');readln(b[j]);



end;

s:=0; I:=1; m:=0;

for j:=1 to n do

begin


if (a[j]=0) or (a[j]=b[i]) then s:=s+1;

if S=b[i] then i:=i+1;

end;

if s=0 then s:=-1;



writeln (' imtixonlarni ',s,' kunda topshirib bo`ladi');

end.
12. Sexirgar Misha Sexirgar Misha pirog tayyorlamoqchi. U tayyorlaydigan pirogga N ta maxsulot kerak bo`ladi.Maxsulotlar 1 dan N gacha nomerlangan.

Har bir maxsulotdan pirog uchun a[i] gramdan kerak bo`ladi.Mishada xar bir maxsulotdan b[i] gramdan bor va undan tashqari K gram sexr bor.Bir gram sexr ishlatib u ixtiyoriy maxsulotdan 1 gram paydo kiladi.Endi Misha bilmokchiki o`zidagi maxsulotlardan va K gram sexrdan foydalanib ko`pi bilan qancha pirog tayyorlashi mumkin.

Kiruvchi ma`lumotlar : 1- katorda N va K Butun sonlar.2- katorda a[i] ketmaketlik xar bir maxsulotdan necha gram kerakligi. 3- katorda N ta b[i] ketma-ketlik Mishadagi bor maxsulotlar



Kiruvchi ma`lumotlar

CHiquvchi ma`lumotlar

  1. 1

2 1 4

11 3 16


4

  1. 3

4 3 5 6

11 12 14 20



3

program sehrgar; uses crt;

label 1;

var n,k,i,t,m,s: integer;

a,b,c: array [1..5] of integer;

begin


write(' kerak bo`ladigan maxsulotlar sonini kiriting ');readln(n);

write(' necha gram sehr bor');readln(k);

for i:=1 to n do

begin


write('A(',i,')=');readln(a[i]);

write('b(',i,')=');readln(b[i]);

end;

t:=0;


1: for i:=1 to n do

begin


b[i]:=b[i]-a[i];

end;


t:=t+1;

for i:=1 to n do

begin

if (b[i]<=0) and (k>0) then begin m:=a[i]-b[i];b[i]:=b[i]+m;k:=k-m;end;



if b[i]=0 then s:=1;

end;


if s=1 then writeln('t=',t) else goto 1;

end.






Download 0.69 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling