Tổng số bài gửi : 152 Join date : 23/04/2022 Age : 41 Đến từ : THPT Chuyên Nguyễn Tất Thành - Yên Bái
Tiêu đề: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Wed Jun 15, 2022 10:36 pm
Các em hoàn thiện 08 bài tập và lần lượt nộp vào đây nhé. Hạn 4 bài đầu: 23h16/6/2022 Thầy chúc các em học tốt!
hoangphuc01122008
Tổng số bài gửi : 151 Join date : 03/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 8:59 am
nfind
Code:
program nfind; var m,i : longint; c : array[1..100000]of longint; k : longint; procedure phantich ( u : longint); var i : longint; begin i := 2; k := 0; while i*i <= u do if u mod i = 0 then begin inc(k); c[k]:= i ; u :=u div i ; end else inc(i); if u > i then begin inc(k); c[k] := u; end; end; begin readln(m); phantich(m); for i := 1 to k do if c[i] <> c[i+1] then write(c[i], #32); end.
hoangphuc01122008
Tổng số bài gửi : 151 Join date : 03/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 10:51 am
Code:
program numberc; var n : longint; c:array [1..100000] of longint; function snt( u : longint ): boolean; var j : longint; begin if u <= 1 then exit(false); if ( u = 2 ) or ( u = 3 ) then exit(true); for j := 2 to trunc(sqrt(u)) do if ( u mod j = 0 ) then exit(false); exit(true); end;
begin readln(n); while ( snt(n) = false) and (n > 0 ) do begin n := n div 10; if n > 0 then writeln(n) else writeln('-1'); end; end.
buitienmanh2008
Tổng số bài gửi : 121 Join date : 08/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 1:30 pm
tsnt
Code:
program tsnt; var n,i,k:longint; c:array[1..1000000]of longint; procedure phantich(u:longint); var i:longint; begin k:=0; i:=2; while i*i<=u do if u mod i=0 then begin k:=k+1; c[k]:=i; u:=u div i; end else i:=i+1; if u>1 then begin k:=k+1; c[k]:=u; end; end; begin readln(n); phantich(n); for i:=1 to k do write(c[i],#32); end.
hoangphuc01122008
Tổng số bài gửi : 151 Join date : 03/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 2:13 pm
Code:
program arrdel; var n,i,k : longint; a,c : array [1..100000] of longint; begin readln(n); for i := 1 to n do readln(a[i]); k := 0; for i := 1 to n do if a[i] = a[i+1] then begin inc(k); c[k] := a[i]; end; for i := 1 to k do write(c[i], #32) end.
buitienmanh2008
Tổng số bài gửi : 121 Join date : 08/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 4:21 pm
nfind
Code:
program nfind; var m,k,i:longint; c:array[1..100000]of longint; procedure phantich(u:longint); var i:longint; begin i:=2; k:=0; while i*i<=u do if u mod i=0 then begin k:=k+1; c[k]:=i; u:=u div i; end else i:=i+1; if u>i then begin k:=k+1; c[k]:=u; end; end; begin readln(m); phantich(m); for i:= 1 to k do if c[i]<>c[i+1] then write(c[i],#32); end.
buitienmanh2008
Tổng số bài gửi : 121 Join date : 08/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 4:51 pm
numberc
Code:
program numberc; var n:longint; c:array[1..10000000]of longint; function ngto(u:longint):boolean; var i:longint; begin if u<=1 then exit(false); if (u=2) or (u=3) then exit(true); for i:=2 to trunc(sqrt(u)) do if (u mod i=0) then exit(false); exit(true); end; begin readln(n); while (ngto(n)=false)and(n>0) do begin n:=n div 10; if n>0 then begin if n>0 then write(n) else write('-1'); end; end; end.
buitienmanh2008
Tổng số bài gửi : 121 Join date : 08/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 5:38 pm
arrdel
Code:
program arrdel; var n,i,k:longint; a,c:array[1..1000000]of longint; begin readln(n); for i:=1 to n do readln(a[i]); k:=0; for i:=1 to n do if a[i]=a[i+1] then begin k:=k+1; c[k] := a[i]; end; for i:=1 to k do write(c[i],#32); end.
Kiệt Quảng
Tổng số bài gửi : 37 Join date : 25/05/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 8:06 pm
Code:
const fi='tsnt.inp'; fo='tsnt.out'; var k,n,i:longint; c:array [0..100] of longint; procedure ptn(n:longint); var i:longint; begin i:=2; while i<=n do if n mod i=0 then begin inc(k); c[k]:=i; n:=n div i; end else inc(i); if n>1 then begin inc(k); c[k]:=n end; end; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); readln(n); ptn(n); for i:=1 to k do write(c[i],#32); close(input); close(output); end.
Kiệt Quảng
Tổng số bài gửi : 37 Join date : 25/05/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 8:06 pm
Code:
const fi='numberc.inp'; fo='numberc.out'; var n,s:longint; function nt(n:longint):boolean; var i:longint; begin if n<=1 then exit(false); if (n<=3) and (n>1) then exit(true); for i:=2 to trunc(sqrt(n)) do if n mod i =0 then exit(false); exit(true); end; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); readln(n); n:=n div 10; while n>0 do begin if nt(n) then s:=n; n:=n div 10; end; if s<>0 then write(s) else write(-1); close(input); close(output); end.
Kiệt Quảng
Tổng số bài gửi : 37 Join date : 25/05/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Thu Jun 16, 2022 8:06 pm
Code:
const fi='arrdel.inp'; fo='arrdel.out'; var i,n:longint; a:array [0..1000] of longint; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); readln(n); for i:=1 to n do read(a[i]); for i:=1 to n do if a[i]<>a[i+1] then write(a[i],#32); close(input); close(output); end.
TrannQuanggDatt2008
Tổng số bài gửi : 70 Join date : 16/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 7:30 pm
TSNT
Code:
Var n: longint; Function TachSo(i: longint): longint; Begin I:=2; While n>1 do Begin If n mod i = 0 then Begin Write(i,#32); N:= n div i End Else i:=i+1; End; End; Begin Assign(Input,'TSNT.INP'); Assign(Output,'TSNT.OUT'); Reset(Input); Rewrite(Output); Readln(n); Write(TachSo(n)); Close(Input); Close(Output); End.
TrannQuanggDatt2008
Tổng số bài gửi : 70 Join date : 16/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 7:32 pm
QSORT
Code:
Var a:array[0..10000]of longint; n,k,c:longint; Procedure sort(l,r: longint); Var i,j,x,y: longint; Begin I:=l; J:=r; X:=a[(l+r) div 2]; Repeat While a[i]<x do Inc(i); While x<a[j] do Dec(j); If not(i>j) then Begin Y:=a[i]; A[i]:=a[j]; A[j]:=y; Inc(i); J:=j-1; End; Until i>j; If l<j then Sort(l,j); If i<r then Sort(i,r); End; Begin Assign(Input,'QSORT.INP'); Assign(Output,'QSORT.OUT'); Reset(Input); Rewrite(Output); Readln(n); C:=n; For k:=1 to n do read(a[k]); Sort(1,n); For k:=1 to c do write(a[k],' '); Close(Input); Close(Output); End.
Admin likes this post
TrannQuanggDatt2008
Tổng số bài gửi : 70 Join date : 16/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 7:59 pm
BubbleSort
Code:
Var n,i: longint; a: array[-7..100007] of longint; Procedure BBS(); Var tam,i,j: longint; Begin 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],#32); End; Begin Assign(Input,'BUBBLESORT.INP'); Assign(Output,'BUBLESORT.OUT'); Reset(Input); Rewrite(Output); Readln(n); For i:=1 to n do read(a[i]); BBS(); Close(Input); Close(Output); End.
Admin likes this post
hoangphuc01122008
Tổng số bài gửi : 151 Join date : 03/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:10 pm
Code:
program qsort; var i, n: Longint; a : array[1..10000000] of Longint; procedure sapsep (u: Longint); var i, j, tam : Longint; begin 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]); end; begin readln(n); for i := 1 to n do readln(a[i]); sapsep(a[i]); end.
Admin likes this post
buitienmanh2008
Tổng số bài gửi : 121 Join date : 08/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:13 pm
qsort
Code:
program qsort; var n,i:longint; a:array[1..1000000]of longint; procedure sapxep(); var i,j,tam:longint; begin 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],#32); end; begin readln(n); for i:=1 to n do readln(a[i]); sapxep(); readln; end.
Admin likes this post
nguyentrungdungqt
Tổng số bài gửi : 153 Join date : 08/06/2022 Age : 14 Đến từ : yên bái
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:26 pm
var a,b:longint; p,c,s:real; begin readln(a,b); c:=sqrt(sqr(a)+sqr(b)); p:=(a+b+c)/2; s:=sqrt(p*(p-a)*(p-b)*(p-c)); write(s:0:2); end.
Admin likes this post
Kiệt Quảng
Tổng số bài gửi : 37 Join date : 25/05/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:29 pm
Code:
const fi='qsort.inp'; fo='qsort.out'; var n,i:longint; a:array [0..1000] of longint; procedure qsort(l,r:longint); var i,j,tg,chot,giua:longint; begin i:=l; j:=r; giua:=(i+j) div 2; chot:=a[giua]; while i<=j do begin while a[i]<chot do inc(i); while a[j]>chot do dec(j); if i<=j then begin tg:=a[i]; a[i]:=a[j]; a[j]:=tg; inc(i); dec(j); end; end; if i<r then qsort(i,r); if l<j then qsort(l,j); end; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); readln(n); for i:=1 to n do read(a[i]); qsort(1,n); for i:=1 to n do write(a[i],#32); close(input); close(output); end.
Admin likes this post
hoangphuc01122008
Tổng số bài gửi : 151 Join date : 03/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:33 pm
qsort
Code:
program sap_xep_nhanh; var n ,i : Longint; a : array[1..1000000] of Longint; procedure qsort(l,r :Longint); var i, j, t, chot, giua: Longint; begin i := l; j := r; giua := (i + j) div 2; chot := a[giua]; while i <= j do begin while a[i] < chot do inc(i); while a[j] > chot do dec(j); if i <= j then begin t := a[i]; a[i] := a[j]; a[j] := l ; inc(i); dec(j); end;
end; end; begin readln(n); for i := 1 to n do read(a[i]); qsort(1,n); for i := 1 to n do write(a[i]); end.
buitienmanh2008
Tổng số bài gửi : 121 Join date : 08/06/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:42 pm
qsort nhanh
Code:
program sap_xep_nhanh; var n,i:longint; a:array[1..10000000] of longint; procedure qsort(l,r:Longint); var i,j,t,chot,giua:longint; begin i:=l; j:=r; giua:=(i+j) div 2; chot:=a[giua]; while i<=j do begin while a[i]<chot do inc(i); while a[j]>chot do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=l ; inc(i); dec(j); end; for i:=1 to n do write(a[i]); end; end; begin readln(n); for i:=1 to n do read(a[i]); qsort(i,n); end.
Kiệt Quảng
Tổng số bài gửi : 37 Join date : 25/05/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:49 pm
Code:
const fi='ilucky.inp'; fo='ilucky.out'; var n,i,l,r,k:longint; a:array [0..1000] of longint; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); readln(n); for i:=1 to n do read(a[i]); for i:=1 to n do r:=r+a[i]; for i:=0 to n do begin if l=r then begin write(i,#32); k:=1; end; l:=l+a[i+1]; r:=r-a[i+1]; end; if k=0 then write(-1); close(input); close(output); end.
Kiệt Quảng
Tổng số bài gửi : 37 Join date : 25/05/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:49 pm
Code:
uses math; const fi='pmin.inp'; fo='pmin.out'; var i,n,res:longint; a:array [0..1000] of longint; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); readln(n); res:=high(longint); for i:=1 to n do begin read(a[i]); res:=min(res,a[i]); end; for i:=1 to n do if res=a[i] then write(i,#32); close(input); close(output); end.
Kiệt Quảng
Tổng số bài gửi : 37 Join date : 25/05/2022
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:49 pm
Code:
uses math; const fi='psecond.inp'; fo='psecond.out'; var i,res,res2,n:longint; a:array [0..1000] of longint; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); readln(n); res:=high(longint); res2:=high(longint); for i:=1 to n do begin read(a[i]); res:=min(res,a[i]); end; for i:=1 to n do if a[i]>res then res2:=min(res2,a[i]); if res2=high(longint) then write(-1) else for i:=1 to n do if res2=a[i] then write(i,#32); close(input); close(output); end.
nguyentrungdungqt
Tổng số bài gửi : 153 Join date : 08/06/2022 Age : 14 Đến từ : yên bái
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 8:56 pm
var x1,y1,x2,y2,x3,y3:longint; p1,p2,s2,s1,x4,y4,d1,d2,d3,d4,d5:real; begin readln(x1,y1,x2,y2,x3,y3); d1:=sqrt(sqr(x2-x1)+sqr(y2-y1)); d2:=sqrt(sqr(x3-x1)+sqr(y3-y1)); d3:=sqrt(sqr(x3-x2)+sqr(y3-y2)); x4:=(x3+x1)/2; y4:=(y3+y1)/2; d4:=1/2*d2; d5:=sqrt(sqr(d1)+sqr(d4)); p1:=(d1+d4+d5)/2; s1:=sqrt(p1*(p1-d1)*(p1-d2)*(p1-d3)); p2:=(d3+d4+d5)/2; s2:=sqrt(p2*(p2-d3)*(p2-d4)*(p2-d5)); write(s1,#32,s2) end.
nguyentrungdungqt
Tổng số bài gửi : 153 Join date : 08/06/2022 Age : 14 Đến từ : yên bái
Tiêu đề: Re: Buổi 3-4. Ngôn ngữ lập trình cơ bản (08 bài) Fri Jun 17, 2022 9:27 pm