1. Trang chủ
  2. » Cao đẳng - Đại học

De HSG Tin 1314

8 2 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

Câu 1:4đ Một số n gọi là số phản nguyên tố nếu số ước số của nó là nhiều nhất trong n số tự nhiên đầu tiên... ĐÁP ÁN Program Bai2;3đ a program tonggiai; uses crt;..[r]

(1)ĐỀ KHẢO SÁT HỌC SINH GIỎI TỈNH MÔN : TIN HỌC Thời gian 150 phút ( Không kể thời gian giao đề ) Ngày thi 28 tháng 02 năm 2014 (HỌC SINH THỰC HÀNH TRÊN MÁY TÍNH Lưu bài làm vào thư mục D:\CHONHSG\ BAI ) PHÒNG GD& ĐT TAM NÔNG Câu 1:(4đ) Một số n gọi là số phản nguyên tố số ước số nó là nhiều n số tự nhiên đầu tiên Cho số K (K <= tỷ) Hãy ghi số phản nguyên tố lớn nhỏ K Câu 2:(6đ) Giai thừa số cho công thức sau: n!=1*2*…*n Cho số N (N<=2.109) nguyên dương a) VCT tính tổng giai thừa các chữ số N b) Tính số chữ số tận cùng N!=1*2*….*N, kết đưa màn hình gồm số là số chữ số tận cùng N! tìm Câu 3:(6đ) Cho mảng A các số nguyên gồm n phần tử Viết chương trình thực các công việc sau: a) Nhập số tự nhiên K Hãy xuất các phần tử có số lần xuất dãy A từ K lần trở lên ( Mỗi số xuất lần) b) Đếm và tính tổng các phần tử khác dãy c) Tìm dãy (an) dãy có tổng nhỏ chia hết cho Câu 4:(4đ) Một chuỗi kí tự định nghĩa là chuổi bao gồm các kí tự ‘A’ ‘Z’ ‘a’ ‘z’ Một xâu có thể viết thu gọn, bao gồm các ký tự kèm theo số lần xuất liên tiếp ký tự đó Viết chương trình nhập chuỗi không quá 255 ký tự từ bàn phím là dạng hay dạng thu gọn - Nếu là chuỗi thì hãy chuyển đổi nó dạng thu gọn - Nếu là chuỗi thuộc dạng thu gọn thì hãy chuyển đổi nó trở lại dạng tương ứng Ví dụ: Chuỗi nhất: AABBCDDEEF -> Chuỗi thu gọn: 2A2BC2D2EF Chuỗi thu gọn: A5B3D2E Chuỗi nhất: ABBBBBDDDEE HẾT Chú ý : Học sinh không sữ dụng tài liệu (2) ĐÁP ÁN Program Bai2;(3đ) a) program tonggiai; uses crt; var SUM:longint;x,n,t:integer; function GT(n:integer):Longint; var i:integer;T:longint; begin if n=0 then T:=1 else begin T:=1; for i:=1 to n T:=T*i; end; GT:=T; end; begin clrscr; write('Nhap n='); readln(N); sum:=0; t:=n; while n>0 begin x:=n mod 10; SUM:=SUM+GT(x); n:=n div 10; end; write('Giai thua cua ',t,'=',sum); readln end b) program tonggiai; uses crt; var SUM:longint;t,i,n:integer; s:string; function GT(n:integer):Longint; var i:integer;T:longint; begin if n=0 then T:=1 else begin T:=1; for i:=1 to n T:=T*i; end; (3) GT:=T; end; begin write('Nhap n='); readln(N); SUM:=GT(n); t:=0; str(SUM,s); {Hàm str(SUM,s) đổi số SUM thành xâu S để đếm số cuối xâu} i:=length(s); while s[i]='0' begin inc(t); dec(i); end; writeln('Cho so o tan cung cua ',N,'=',t); readln end (4) Progaram bai3;(3đ) es crt; var a,b:array[0 100] of integer; n,j,i,k:integer; f:text; Procedure docf; begin assign(f,'C:\DAYSO.INP'); reset(f); i:=0; read(f,n); readln(f,k); While not eof(f) begin inc(i); read(f,a[i]); end; close(f); end; Procedure xuly; begin assign(f,'C:\DAYSO.OUT'); rewrite(f); FillChar(b,SizeOf(b),0); For i:=1 to n inc(b[a[i]]); For i:=1 to n if b[i]<>0 then if b[i]>=k then writeln(f,i,' Xuat hien ',b[i], ' lan!'); close(f); end; BEGIN clrscr; docf; xuly; readln end Progam Bai4;(4đ) program Nen_giainen_chuoi; var s:string; i,k:integer; function Nen(s:string):string; var i,j,d:integer; c:string; begin for i:=1 to length(s)-1 if s[i]=s[i+1] then begin d:=2; for j:=i+1 to length(s) if (s[i]=s[j+1]) and (j<length(s)) then d:=d+1 else begin str(d,c); insert(c,s,i); delete(s,i+1,d-1); break; end; end; nen:=s; (5) end; function Giainen(s:string):string; var i,j,d,code:integer; c,x:string; begin for i:=1 to length(s) if s[i] in ['0' '9'] then c:=c+s[i] else begin val(c,d,code); for j:=1 to d x:=x+s[i]; c:=''; d:=0; end; giainen:=x; end; begin readln(s); for i:=1 to length(s) if s[i] in ['0' '9'] then begin k:=1; break; end; if k=1 then writeln(giainen(s)) else writeln(nen(s)); readln end (6) Nguyen Thu Huong - NQB Bài 1: Uses crt; var m,i,c,tam,k:integer; function demuoc(var n:integer):integer; var c,i:integer; begin c:=0; for i:=1 to n if n mod i =0 then c:=c+1; demuoc:=c; end; begin clrscr; write(‘Nhap k:’);readln(k); m:=0; for i:=1 to k if demuoc(i)> m then begin m:=demuoc(i); tam:=i; end; write('so phan nguyen to lon nhat <= ‘,k,’ la: ',tam); readln; end Uses crt; var m,i,c,tam,k:integer; function demuoc(var n:integer):integer; var c,i:integer; begin c:=0; for i:=1 to n if n mod i =0 then c:=c+1; demuoc:=c; end; begin clrscr; write('Nhap k:');readln(k); m:=0; for i:=1 to k if demuoc(i)> m then begin m:=demuoc(i); tam:=i; end; write('so phan nguyen to lon nhat <= ',k,' la: ',tam); readln; end Bài 4: uses crt; var s,ss,st,si:string; i,j,l:integer; function kttn(s:string):boolean; var x:char; ok:boolean; begin kttn:=true; for i:=1 to length(s) s[i]:=upcase(s[i]); for i:=1 to length(s) begin ok:=false; for x:='A' to 'Z' if s[i]=x then ok:=true; if not ok then begin kttn:=false;break;end; end; (7) end; procedure nen(s:string;var st:string); begin ss:=''; while s<>'' begin i:=1; while (s[i+1]=s[1])and(i<length(s)) inc(i); if i>1 then begin str(i,si); ss:=ss+s[1]+si; end else ss:=ss+s[1]; delete(s,1,i); end; s:=ss;l:=2; while l<length(s) begin i:=1; while i<=length(s)-l begin si:=copy(s,i,l); j:=i+l; ss:=copy(s,j,l); while ss=si begin j:=j+l; ss:=copy(s,j,l); end; if j=i+l then inc(i) else begin str((j-i)div l,ss); delete(s,i,j-i); si:='('+si+')'+ss; insert(si,s,i); i:=i+l+2+length(ss); end; end; inc(l); end; st:=s; end; function ktcd(st:string):boolean; begin ktcd:=false; for i:=1 to length(st) if st[i]='(' then begin ktcd:=true; break; end; end; procedure giainen(st:string;var s:string); var d,c:byte; code:integer; begin while ktcd(st) begin i:=1; c:=0; while st[i]<>'(' inc(i); d:=1; j:=i+1; while c<d begin inc(j); if st[j]='(' then inc(d); if st[j]=')' then inc(c); end; si:=copy(st,i,j-i+1); (8) delete(st,i,j-i+1); delete(si,1,1); delete(si,length(si),1); j:=i; while st[j+1] in['0' '9'] inc(j); ss:=copy(st,i,j-i+1); delete(st,i,j-i+1); val(ss,l,code); for j:=1 to l insert(si,st,i); end; i:=1; while i<=length(st) begin inc(i); if st[i] in['0' '9'] then begin j:=i; while st[j+1] in['0' '9'] inc(j); ss:=copy(st,i,j-i+1); delete(st,i,j-i+1); val(ss,l,code); ss:=st[i-1]; for j:=1 to l-1 insert(ss,st,i); i:=i+l-1; end; end; s:=st; end; begin clrscr; write('nhap chuoi: ');readln(s); if kttn(s) then begin nen(s,st); writeln('Chuoi sau nen la: ',st); giainen(st,s); writeln('Chuoi sau giai nen la: ',s); end else write('Xau ko thuan nhat.'); readln; end (9)

Ngày đăng: 14/09/2021, 10:10

w