377
1
2
1
2
0
0
Yechish:
1- usul. Masalani A va B massivlar asosida
hosil qilingan
to‘plamlar yordamida hal etish mumkin.
2- usul.
A massivning har bir elementi B
massivda borligi va B
massivning har bir elementi A massivda borligini tekshiramiz.
Dasturi:
Program usul_1;
Type Toplam =
Set of Byte;
Var A, B: Toplam; k, N, M,Q: byte;
Begin A:=[]; B:=[]; {Bo‘sh to‘plamlar}
Write(‘N=’); ReadLn(N); Write(‘M=’); ReadLn(M);
Writeln(‘ A massiv elementlarini kiriting: ‘);
For k:=1 To N Do begin Write(‘A[‘,k,’]=’); ReadLn(Q);
A:= A + [Q]; end; {A to‘plamni hosil qilish}
Writeln(‘ B massiv elementlarini kiriting: ‘);
For k:=1 To M Do begin Write(‘B[‘,k,’]=’); ReadLn(Q);
B:= B + [Q]; end; {B to‘plamni hosil qilish}
IF A=B THEN Write(‘ 1 ‘) ELSE Write(‘ 0);
End.
Program usul_2;
Var A, B: array [1..255]
of Integer; k, s, N, M,Q: byte; bor:
Boolean;
Begin
Write(‘N=’); ReadLn(N); Write(‘M=’); ReadLn(M);
Writeln(‘ A massiv elementlarini kiriting: ‘);
For k:=1 To N Do begin Write(‘A[‘,k,’]=’); ReadLn(A[k]); end;
Writeln(‘ B massiv elementlarini kiriting: ‘);
For s:=1 To M Do begin Write(‘B[‘,s,’]=’); ReadLn(B[s]); end;
For k:=1 To N Do BEGIN Bor:=True; For s:=1 To M Do
IF A[k]=B[s] THEN Bor:=False;
IF Bor THEN begin Write(‘ 0’); Readln; Halt; end; END;
For s:=1 To M Do BEGIN Bor:=True; For k:=1 To N Do
IF B[s]=A[k] THEN Bor:=False;
378
IF Bor THEN begin Write(‘ 0’); Readln; Halt; end; END;
Write(‘ 1’);Readln;
End.