Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
Bài làm của bạn @lê chí hiếu(bạn được 2,1 điểm)
bài 1
program PTYN;
uses crt;
var a:array[1..100,1..100]of integer;
i,j,m,n:integer;
f1,f2:text;
Max, Min:Integer;
Kt:boolean;
Procedure XuatMang;
begin
For i:=1 to n do
begin
for j:=1 to m do
Write(a[i,j]:4);
Writeln;
end;
end;
Procedure MaxCot(l:Integer);
var p:Integer;
begin
Max:=A[1,l];
For p:=2 to n do
if A[p,l]>Max then Max:=A[p,l];
end;
Procedure MinHang(k:Integer);
var o:integer;
begin
Min:=A[k,1];
For o:=2 to n do
if A[k,o]<Min then Min:=A[k,o];
end;
begin
clrscr;
assign(f1,'ptyn.inp');
assign(f2,'ptyn.out');
reset(f1);rewrite(f2);
while not EOF(f1) do
begin
kt:=false;
readln(f1,n,m);
for i:=1 to n do
begin
for j:=1 to m do
Read(f1,a[i,j]);
readln(f1);
end;
for i:=1 to n do
begin
for j:=1 to n do
begin
MaxCot(j);
MinHang(i);
if Max=Min then
begin
Writeln(f2,'(',i,',',j,')');
kt:=true;
end;
end;
end;
If kt=false then Writeln(f2,'Khong co ptu yen ngua.');
end;
Close(f1); Close(f2);
Readln
End.
Bài 4
const fi='tvh.inp';
fo='tvh.out';
var n,d,dem,sl,s2cs,s3cs,s4cs,s5cs,s6cs,s7cs,k,i,d1:longint;
st,st1,stk:string;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n,k);
str(n,st);
d:=length(st);
case d of
1: write(9);
2: begin
sl:=n-9;
dem:=9+sl*2;
end;
3: begin
s2cs:=(99-10)+1;
s3cs:=n-99;
dem:=9+s2cs*2+s3cs*3;
end;
4: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=n-999;
dem:=9+s2cs*2+s3cs*3+s4cs*4;
end;
5: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=n-9999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5;
end;
6: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=n-99999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6;
end;
7: begin
s2cs:=(99-10)+1;
s3cs:=(999-100)+1;
s4cs:=(9999-1000)+1;
s5cs:=(99999-10000)+1;
s6cs:=(999999-1000000)+1;
s7cs:=n-999999;
dem:=9+s2cs*2+s3cs*3+s4cs*4+s5cs*5+s6cs*6+s7cs*7;
end;
end;
if k<=dem then
begin
i:=1;
d1:=0;
repeat
str(i,st1);
d1:=d1+length(st1);
i:=i+1;
until d1>=k;
stk:=st1[length(st1)-(d1-k)];
writeln(f2,stk);
end;
close(f1);
close(f2);
end.
Bài 5
PROGRAM robot;
VAR A:ARRAY[0..30,0..30] OF BYTE;
F:ARRAY[0..30,0..30] OF LONGINT;
m,n:INTEGER;
PROCEDURE Enter;
VAR i,j:INTEGER;
BEGIN
readln(m,n);
FOR i:=1 TO m DO
BEGIN
FOR j:=1 TO n DO read(A[i,j]);
readln;
END;
FOR i:=0 TO m DO A[i,0]:=-1;
FOR j:=0 TO n DO A[0,j]:=-1;
END;
FUNCTION Max(a,b:LONGINT):LONGINT;
BEGINIF (a>b) THEN Max:=a ELSE Max:=b;
END;
PROCEDURE Optimize;
VAR i,j:INTEGER;
BEGIN
FOR i:=0 TO m DO F[i,0]:=-1;
FOR j:=0 TO n DO F[0,j]:=-1;
F[0,1]:=0;
FOR i:=1 TO m DO
FOR j:=1 TO n DO
F[i,j]:=2*Max(F[i,j-1],F[i-1,j])+A[i,j];
END;
PROCEDURE Trace(i,j:INTEGER);
BEGINIF (i=1) AND (j=1) THEN
writeln(F[m,n])
ELSE
BEGIN
IF F[i,j-1]>F[i-1,j] THEN
Trace(i,j-1)
ELSE
Trace(i-1,j);
writeln(i,' ',j);
END;
END;
BEGIN
Assign(Input,'Robot.inp'); Reset(Input);
Assign(Output,'Robot.out');Rewrite(Output);
Enter;
Optimize;
Trace(m,n);
close(Input);
close(Output);
END.
Em hiểu,nhưng cách anh chỉ đến 8 chữ số là cùng.
Cách em thì chỉ cần lấy int64(em dùng luôn mấy biến real vì bự hơn) thì chấp 10^30
Program hotrotinhoc_hoc24;
const fi='C:\Input.txt';
fo='C:\Output.txt';
var f: text;
i,n: integer;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,n);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
for i:=1 to n do write(f,i,' ');
close(f);
end;
begin
ip;
out;
end.
const fi='input.txt';
fo='output.txt';
var f1,f2:text;
i,n:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
write(f2,i:4);
close(f1);
close(f2);
end.
uses crt;
var a:array[1..100]of integer;
i,n,t,j,tam:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:5);
writeln;
writeln('Cac so duong la: ');
for i:=1 to n do if (a[i]>0) then write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i] mod 3=0 then t:=t+a[i];
writeln(t);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
for i:=1 to n do write(a[i]:4);
readln;
end.
THAM KHẢO!
1.Thuật toán sắp xếp chèn (Insertion Sort):
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
return arr
A = [5, 8, 1, 0, 10, 4, 3]
sorted_A = insertion_sort(A)
print("Dãy A sau khi sắp xếp chèn:", sorted_A)
2. Thuật toán sắp xếp chọn (Selection Sort):
def selection_sort(arr):
for i in range(len(arr)):
min_idx = i
for j in range(i + 1, len(arr)):
if arr[j] < arr[min_idx]:
min_idx = j
arr[i], arr[min_idx] = arr[min_idx], arr[i]
return arr
A = [5, 8, 1, 0, 10, 4, 3]
sorted_A = selection_sort(A)
print("Dãy A sau khi sắp xếp chọn:", sorted_A)
3.Thuật toán sắp xếp nổi bọt (Bubble Sort):
def bubble_sort(arr):
n = len(arr)
for i in range(n - 1):
for j in range(n - 1 - i):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr
A = [5, 8, 1, 0, 10, 4, 3]
sorted_A = bubble_sort(A)
print("Dãy A sau khi sắp xếp nổi bọt:", sorted_A)
Bài 1:
uses crt;
var a:array[1..100,1..100]of integer;
m,n,i,j,k,g,tam:integer;
begin
clrscr;
write('nhap so n='); readln(n);
write('nhap so m='); readln(m);
for i:=1 to n do
for j:=1 to m do
begin
write('a[',i,',',j,']='); readln(a[i,j]);
end;
{----------------------------------------------------------}
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]:4);
writeln;
end;
{----------------------------------------------------------}
writeln('day tang dan cua ma tran la: ');
for i:=1 to n do
for j:=1 to m do
for k:=1 to n do
for g:=1 to m do
if a[i,j]<a[k,g] then begin
tam:=a[k,g];
a[k,g]:=a[i,j];
a[i,j]:=tam;
end;
writeln;
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]:4);
writeln;
end;
{---------------------------------------------------------}
writeln('day giam dan cua ma tran la: ');
for i:=1 to n do
for j:=1 to m do
for k:=1 to n do
for g:=1 to m do
if a[i,j]>a[k,g] then begin
tam:=a[k,g];
a[k,g]:=a[i,j];
a[i,j]:=tam;
end;
writeln;
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]:4);
writeln;
end;
readln;
end.
Bài 2:
uses crt;
var a:array[1..100,1..100]of integer;
i,j,n,m,snn,sln,vtc,vth,x,z,kt,k:integer;
begin
clrscr;
{----------nhap----------}
write('nhap n: ');readln(n);
write('nhap m='); readln(m);
for i:=1 to n do
for j:=1 to m do
begin
write('a[',i,',',j,']='); readln(a[i,j]);
end;
{----------nho nhat hang----------}
for i:=1 to n do
begin
snn:=a[i,1];
for j:=1 to m do
if snn>=a[i,j] then
begin
snn:=a[i,j];
vth:=i;
vtc:=j;
end;
kt:=0;
sln:=a[vth,vtc];
for k:=1 to n do
if sln<a[k,vtc] then kt:=1;
if kt=0 then writeln(k,',',vtc);
end;
readln;
end.
uses crt;
var a,b:array[1..1000]of longint; d:text; i,j,n,k,t,kt,ktt:longint;
begin
clrscr;
assign(d,'input.pas');reset(d);
readln(d,n);
for i:=1 to n do read(d,a[i]);
k:=0;
for i:=1 to n do
begin
t:=0;
for j:=i to n do
begin
t:=t+a[j];
inc(k,3);
b[k-2]:=i;
b[k-1]:=i+j;
b[k]:=t;
end;
end;
// for i:=1 to k do write(b[i],';'); writeln;
kt:=0;
i:=0;
repeat
inc(i); ktt:=0;
for j:=1 to k do If i=b[j] then ktt:=1;
if ktt=0 then kt:=1;
until kt=1;
writeln(i);
close(d);
readln
end.
Cái test thứ 2 đúng, còn cái test thứ 1 sai rồi bạn ơi phải ra 8 mới đúng mà mình chạy ra 11