Dap an GVG truong 2011
Chia sẻ bởi Chu Thị Hợi |
Ngày 27/04/2019 |
120
Chia sẻ tài liệu: dap an GVG truong 2011 thuộc Tin học 10
Nội dung tài liệu:
Bài 1 - Phần tử yên ngựa
const
Inp = `Bai30.INP`;
Out = `Bai30.OUT`;
MaxLongInt = 2147483647;
var
Min, Max: array[1..5000] of LongInt;
m, n: Integer;
procedure ReadInput;
var
i, j, k: Integer;
hf: Text;
begin
Assign(hf, Inp);
Reset(hf);
Readln(hf, m, n);
for i := 1 to m do Min[i] := MaxLongInt;
for j := 1 to n do Max[j] := -MaxLongInt;
for i := 1 to m do
begin
for j := 1 to n do
begin
Read(hf, k);
if Min[i] > k then Min[i] := k;
if Max[j] < k then Max[j] := k;
end;
Readln(hf);
end;
Close(hf);
end;
procedure WriteOutput;
var
i, j: Integer;
Result: Boolean;
hf: Text;
begin
Result := False;
Assign(hf, Out);
Rewrite(hf);
Writeln(hf, `Cac phan tu yen ngua la: `);
for i := 1 to m do
for j := 1 to n do
if Min[i] = Max[j] then
begin
Result := True;
Write(hf, `(`, i, `,`, j, `); `);
end;
if not Result then
begin
Rewrite(hf);
Write(hf, `Khong co phan tu yen ngua`);
end;
Close(hf);
end;
begin
ReadInput;
WriteOutput;
end.
Bài 2 - Số siêu nguyên tố
Program Bai2;
{SuperPrime};
var a,b: array [1..100] of longint;
N,i,k,ka,kb,cs: byte;
Function Prime(N: longint): boolean;
Var i: longint;
Begin
If (N=0) or (N=1) then
Prime:=false
Else
Begin
i:=2;
While (N mod i <> 0) and (i <= Sqrt(N)) do Inc(i);
If i > Sqrt(N) then
Prime:=true Else Prime:=false;
End;
End;
BEGIN
Write (`Nhap N: `);
Readln (N);
ka:=1; a[ka]:=0;
For i:=1 to N do
Begin
Kb:=0;
For k:=1 to ka do
For cs:=0 to 9 do
If Prime(a[k]*10+cs) then
Begin
Inc(kb);
b[kb]:=a[k]*10+cs;
end;
ka:=kb;
For k:=1 to ka do
a[k]:=b[k]; end;
For k:=1 to ka do
Write(a[k]:10);
Writeln;
Writeln(`Co tat ca`,ka,`so sieu nguyen to co`,N,`chu so.`);
Readln;
END.
Bai 3: CHUSOTHU N
Uses crt;
Const fi =`number.inp`;
fo =`number.out`;
cs:array[1..8] of longint = (9, 180, 2700, 36000, 450000, 5400000, 63000000, 720000000);
Var n : longint;
f,g :text;
Function num(n:longint):char;
var k, so, mu : longint;
s : string;
Begin
k:=1; mu:=1;
while (k<9)and(cs[k] begin
n:=n-cs[k];
inc(k); mu:=mu*10;
end;
if mu=1 then so:=n div k
else so:=n div k+mu+ord(n mod k>0)-1;
str(so,s);s:=s[k]+s;
num:=s[n mod k+1];
End;
BEGIN
assign(f,fi); reset(f);
assign(g,fo); rewrite(g);
while not seekeof(f) do
begin
const
Inp = `Bai30.INP`;
Out = `Bai30.OUT`;
MaxLongInt = 2147483647;
var
Min, Max: array[1..5000] of LongInt;
m, n: Integer;
procedure ReadInput;
var
i, j, k: Integer;
hf: Text;
begin
Assign(hf, Inp);
Reset(hf);
Readln(hf, m, n);
for i := 1 to m do Min[i] := MaxLongInt;
for j := 1 to n do Max[j] := -MaxLongInt;
for i := 1 to m do
begin
for j := 1 to n do
begin
Read(hf, k);
if Min[i] > k then Min[i] := k;
if Max[j] < k then Max[j] := k;
end;
Readln(hf);
end;
Close(hf);
end;
procedure WriteOutput;
var
i, j: Integer;
Result: Boolean;
hf: Text;
begin
Result := False;
Assign(hf, Out);
Rewrite(hf);
Writeln(hf, `Cac phan tu yen ngua la: `);
for i := 1 to m do
for j := 1 to n do
if Min[i] = Max[j] then
begin
Result := True;
Write(hf, `(`, i, `,`, j, `); `);
end;
if not Result then
begin
Rewrite(hf);
Write(hf, `Khong co phan tu yen ngua`);
end;
Close(hf);
end;
begin
ReadInput;
WriteOutput;
end.
Bài 2 - Số siêu nguyên tố
Program Bai2;
{SuperPrime};
var a,b: array [1..100] of longint;
N,i,k,ka,kb,cs: byte;
Function Prime(N: longint): boolean;
Var i: longint;
Begin
If (N=0) or (N=1) then
Prime:=false
Else
Begin
i:=2;
While (N mod i <> 0) and (i <= Sqrt(N)) do Inc(i);
If i > Sqrt(N) then
Prime:=true Else Prime:=false;
End;
End;
BEGIN
Write (`Nhap N: `);
Readln (N);
ka:=1; a[ka]:=0;
For i:=1 to N do
Begin
Kb:=0;
For k:=1 to ka do
For cs:=0 to 9 do
If Prime(a[k]*10+cs) then
Begin
Inc(kb);
b[kb]:=a[k]*10+cs;
end;
ka:=kb;
For k:=1 to ka do
a[k]:=b[k]; end;
For k:=1 to ka do
Write(a[k]:10);
Writeln;
Writeln(`Co tat ca`,ka,`so sieu nguyen to co`,N,`chu so.`);
Readln;
END.
Bai 3: CHUSOTHU N
Uses crt;
Const fi =`number.inp`;
fo =`number.out`;
cs:array[1..8] of longint = (9, 180, 2700, 36000, 450000, 5400000, 63000000, 720000000);
Var n : longint;
f,g :text;
Function num(n:longint):char;
var k, so, mu : longint;
s : string;
Begin
k:=1; mu:=1;
while (k<9)and(cs[k]
n:=n-cs[k];
inc(k); mu:=mu*10;
end;
if mu=1 then so:=n div k
else so:=n div k+mu+ord(n mod k>0)-1;
str(so,s);s:=s[k]+s;
num:=s[n mod k+1];
End;
BEGIN
assign(f,fi); reset(f);
assign(g,fo); rewrite(g);
while not seekeof(f) do
begin
* Một số tài liệu cũ có thể bị lỗi font khi hiển thị do dùng bộ mã không phải Unikey ...
Người chia sẻ: Chu Thị Hợi
Dung lượng: |
Lượt tài: 0
Loại file:
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)