1. Trang chủ
  2. » Giáo án - Bài giảng

tinhoc nd

3 269 0

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

THÔNG TIN TÀI LIỆU

Nội dung

Bai 1 const inp='mh.inp'; out='mh.out'; var fi,fo:text; i,n,k,tong,so:longint; begin assign(fi,inp);reset(fi); assign(fo,out);rewrite(fo); readln(fi,n,k); tong:=0;so:=0; for i:=1 to k do begin tong:=tong+so; read(fi,so); end; write(fo,tong); close(fi);close(fo); end. Bai 2 const inp='gonbac.inp'; out='gonbac.out'; var fi,fo:text; i,n,kq:longint; procedure nhap; begin assign(fi,inp);reset(fi); readln(fi,n); close(fi); end; function nt(x:longint):boolean; var ok:boolean; i1,du:longint; begin ok:=true; du:=x mod 6; if (x>6) and (du in [0,2,3,6]) then ok:=false; if ok then for i1:=2 to trunc(sqrt(x)) do if x mod i1=0 then begin ok:=false; break; end; nt:=ok; end; procedure xuli; begin kq:=0; if n=4 then kq:=1 else begin i:=1; repeat i:=i+2; if nt(i) and (n-i>=i) and nt(n-i) then kq:=kq+1; until i>(n-2)div 2; end; end; procedure xuat; begin assign(fo,out);rewrite(fo); write(fo,kq); close(fo); end; begin nhap; xuli; xuat; end. Bai 32 const inp='xe.inp'; out='xe.out'; var fi,fo:text; sttd,sttv,d,v:array[1 200]of integer; i,j,tg,vt,tong,n,m:integer; procedure nhap; begin assign(fi,inp);reset(fi); readln(fi,n,m); for i:=1 to n do begin read(fi,d[i]); sttd[i]:=i; end; readln(fi); for i:=1 to m do begin read(fi,v[i]); sttv[i]:=i; end; close(fi); end; procedure xuli; begin for i:=1 to n-1 do begin vt:=i; for j:=i+1 to n do if d[vt]<d[j] then vt:=j; tg:=d[vt];d[vt]:=d[i];d[i]:=tg; tg:=sttd[vt];sttd[vt]:=sttd[i];sttd[i]:=tg; end; for i:=1 to m-1 do begin vt:=i; for j:=i+1 to m do if v[vt]>v[j] then vt:=j; tg:=v[vt]; v[vt]:=v[i]; v[i]:=tg; tg:=sttv[vt]; sttv[vt]:=sttv[i]; sttv[i]:=tg; end; tong:=0; for i:=1 to n do tong:=tong+d[i]*v[i]; end; procedure xuat; begin assign(fo,out);rewrite(fo); writeln(fo,tong); for i:=1 to n do for j:=1 to n do if sttd[j]=i then begin write(fo,sttv[j],' '); break; end; close(fo); end; Begin nhap; xuli; xuat; End. . then begin ok:=false; break; end; nt:=ok; end; procedure xuli; begin kq:=0; if n=4 then kq:=1 else begin i:=1; repeat i:=i+2; if nt(i) and (n-i>=i) and nt(n-i) then kq:=kq+1; until i>(n-2)div 2; end; end; procedure. nhap; begin assign(fi,inp);reset(fi); readln(fi,n,m); for i:=1 to n do begin read(fi,d[i]); sttd[i]:=i; end; readln(fi); for i:=1 to m do begin read(fi,v[i]); sttv[i]:=i; end; close(fi); end; procedure xuli; begin for i:=1 to n-1 do begin vt:=i; for. tong:=tong+d[i]*v[i]; end; procedure xuat; begin assign(fo,out);rewrite(fo); writeln(fo,tong); for i:=1 to n do for j:=1 to n do if sttd[j]=i then begin write(fo,sttv[j],' '); break; end; close(fo); end; Begin nhap; xuli; xuat; End.

Ngày đăng: 21/01/2015, 14:00

Xem thêm

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w