Программирование на языке Pascal - ответы
Количество вопросов - 181
{массив а хранит веса всех предметов, в порядке их ввода, half - "большая" половина суммы всех весов, dif - отклонение текущей найденной суммы от half}procedure rec(k: byte; sum: longint; var dif: longint);var i: byte;begin if sum+a[k]<=half then for i:= k+1 to n do rec(i,sum+a[k],dif) else if half-sum<dif then begin dif:= half-sum; if dif<2 then out(dif){печать и завершение} endend;
(a-b)*(c+(x-y)/d)+(k*m-(n/s+t))
for i:= 1 to N do set_res[i]:= set1[i] and set2[i]
for i:= 2 to N do begin x:= a[i] for j:= i-1 downto 1 do if a[j]>x then a[j+1]:= a[j] else break a[j+1]:= x; end;
{type ssylka = ^spisok; spisok = record znach: integer; next,prev: ssylka end;var head,p,q: ssylka;}while (head<>nil)and(head^.znach =0)do begin p:= head; head:= head^.next; dispose(p); end;if head<>nil then begin head^.prev:= nil; p:= head; while p^.next <> nil do if p^.next^.znach = 0 then begin q:= p^.next; p^.next:= q^.next; if p <> tail then [???]; dispose(q); end else p:= p^.next; end else tail:= nil;
a ga db cc hf bf c
z:= -1;if a<100 then if a<10 then if a<1 then z:=0 else z:= 10 else z:= 100;
for i:= k to k+10 do a:= a+2
procedure p(var a: byte; const b: char; x: real);являются неправильными с точки зрения компилятора языка Pascal?
type data = record day: 1..31; month: 1..12; year: 1900.. 2100; end; person = record name: string[20]; date_birth: data; case family_status: char of 'm': (wedding_date: data; spouse_name: string[20]); 's': (church_celibate: boolean); 'd': (date_divorce: data;); 'w': (date_of_spouse_death: data); end;
function C: boolean; forward;function D: boolean; forward;procedure A; begin x:= c(x); y:= d(y); end;function B: boolean; begin z:= d(z); end;function C; begin z:= b(z); end;function D; begin z:= b(z); end;
{s: string; i,k,t: byte}res:= ''; t:= byte(s[0]);if k+i > t+1 then k:= t-i;if i <= t then for j:= i to i+k do res:= res + s[j];
a: b cb: cc: gd: c gf: dh: b
var a: byte;proc p1(var k: byte);proc p2(t: byte); begin t:= t*2 end;var a: byte; begin a:= 1; k:= 5; p2(k); end;begin a:= 10; p1(a);end.
a * b + not c > a mod c * a shl b xor aне меняют порядок выполнения операций?
z:= -10;if a>0 then if a>100 then if a>200 then z:=0 else z:= 20 else z:=100;
for i:= 2 to n do begin min:= a[i-1]; for j:= i to n do if a[j]<= min then begin min:= a[j]; k:=j end; x:= a[i-1]; a[i-1]:= a[k]; a[k]:= x; end;
{s1,s2: string; i,j,t1,t2: byte}i:=0;res:= ''; t1:= byte(s1[0]);t2:= byte(s2[0]);if i > t2 then i:= t2+1;for j:= 1 to i-1 do res:= res + s2[j];for j:= 1 to t1 do res:= res + s1[j];for j:= i to t2 do res:= res + s2[j];
readln(f,s,k); {s: string[22], k:shortint =0}
var a: integer; r1: record a: longint; ... end; r2: record a: byte; ... end;begin a:= 0; with r2 do begin a:= 10; with r1 do begin a:= -r2.a; r2.a:= 100; end; a:= r1.a; end; a:= -100;end.
rewrite(f);for c:= 'а' to 'р' do write(f,c); {c: char}seek(f,10);read(f,c);truncate(f);seek(f,15);write(f,c);
procedure p(x:real; const c: byte; var d: integer);являются неправильными с точки зрения компилятора языка Pascal?
program prog;var a: byte;procedure p1; var a: byte; begin ... end;procedure p2; function f: boolean; var a: byte; begin ... end; var a: byte; begin ... end;
var a: byte;proc p1(var t: byte); begin t:= t*2 end;proc p2(var k: byte);var a: byte; begin a:= 1; k:= 5; p1(k); end;begin a:= 10; p2(a);end.
{массив а хранит веса всех предметов, в порядке их ввода, half - "большая" половина суммы всех весов, dif - отклонение текущей найденной суммы от half}procedure rec(k: byte; sum: longint; var dif: longint);var i: byte;begin if sum+a[k]<=half then for i:= k+1 to n do rec(i,sum+a[k],dif) else if half-sum<dif then begin dif:= half-sum; if dif<2 then out(dif){печать и завершение} endend;
0!! =11!! = 1n!! = n*(n-2)!!, для любого натурального n.
{b: string; p: ^integer}b:= ‘БББ’;p:= addr(b[1]);a:= p^;
a b c d fa 0 12 5 12 3b 12 0 15 0 7c 5 15 0 10 20d 12 0 10 0 2f 3 7 20 2 0
x*(a+b*c–g)+((m-n)*t*d/(s-y))*z
a: b db: d ff: c d gd: h gh: g
const nnn = 10000;type uk = ^ukk; ukk = record v: integer; next: uk; end;var head: array[1..nnn] of uk; a: array[1..nnn] of integer; ii,i,j,k,n: integer; q,p: uk; f: text;procedure dob(ii,jj: integer); {добавление ребра}var pp,qq: uk;begin new(qq); qq^.v:=jj; qq^.next:=nil; if head[ii]=nil then head[ii]:=qq {вставка первого} else begin {вставка остальных} pp:=head[ii]; while pp^.next<>nil do pp:=pp^.next; pp^.next:=qq; end;end;begin{------- считывание графа ------------} ... readln(f,n); {кол-во вершин в графе} while not eof(f) do begin read(f,i,j); if i<>j then begin dob(j,i); dob(i,j); end; end;{--------- инициация массива ---------} for i:=1 to n do begin head[i]:=nil; a[i]:=0; end;{------- основная часть -------------} k:=0; i:=1; repeat k:=k+1; a[i]:=k; p:=head[i]; while p<>nil do begin j:=p^.v; a[j]:=k; if (head[j]<>nil) and (i<>j) then begin q:=p; while q^.next<>nil do q:=q^.next; q^.next:=head[j]; head[j]:=nil; end; p:=p^.next; end; i:=i+1; while (head[i]=nil) and (i<=n) do i:=i+1; until i=n+1; for i:=1 to n do if a[i]=0 then k:=k+1; writeln(k); {выдача результата}end.
unit A; unit C; unit F; interface interface interface uses C,D; uses D,F; var f; var a; var c; implementationimplementation implementation uses A; uses F; uses B; var ff; var aa; var cc; end;end; end;unit B; unit D; interface interface uses C; var d; var b; implementationimplementation uses B; uses D; var dd; var bb; end; end;
1) while not eof(f) do begin inc(n); read(f,a[n]); inc(obsh_ves,a[n]); end;close(f);min:= MaxLongInt;2) while head<>nil do beginwith head^.e^ doif from^.dist+len < toward^.dist then begintoward^.dist:= from^.dist + len;enqueue(toward,queue,head);end;next_head:= head ^.next;dispose(head);head:= next_headend;3) while left<=right do begin sred:= (left+right)div 2; if a[sred]<x then left:= sred+1 else begin right:= sred-1; inc(k); end; end; for j:= i-1 downto left do a[j+1]:= a[j];4) while p<>nil do begin j:=p^.v; a[j]:=k; if (head[j]<>nil) and (i<>j) then begin q:=p; while q^.next<>nil do q:=q^.next; q^.next:=head[j]; head[j]:=nil; end; p:=p^.next; end;
for i:= 1 to n-1 do begin x:= a[i+1]; l:= 1; r:= i; while l<=r do begin s:= (l+r)div 2; if a[s]<x then l:= s+1 else r:= s-1; end; for j:= i downto 0 do a[j]:= a[j+1]; a[l]:= x; end;
{b: string; p: ^word}b:= ‘ААББВВГГДД’;p:= addr(b[7]);a:= p^;
type data = record day: 1..31; month: 1..12; year: 1900.. 2100; end; man = record name: string[20]; date_birth: data; case citizen: boolean of true: (birth_place: string[20]); false: (country: string[20]; date_came: data); end;
rewrite(f);for c:= 'a' to 'p' do write(f,c); {c: char}seek(f,10);read(f,c);write(f,c);seek(f,15);truncate(f);write(f,c);
for i:= 2*k to 5*k do a:= a*2
type vertices = ^vertex; edges = ^edge; vertex = record id,dist: integer; incidence: edges; next: vertices; end; edge = record from,toward: vertices; len: integer; next: edges; end; ptr_edges = ^ptr_edge; ptr_edge = record e: edges; next: ptr_edges; end;var i,j,len,source_id: integer; g,source: vertices; queue,head,next_head: ptr_edges; f: text;function new_vertex(i: integer; g: vertices): vertices;var v: vertices;begin new(v); v^.id:= i; v^.dist:= maxint; v^.incidence:= nil; v^.next:= g; new_vertex:= vend;function find_vertex(i: integer; g: vertices): vertices;var v: vertices;begin v:= g; while (v<>nil)and(v^.id<>i) do v:= v^.next; find_vertex:= vend;function find_edge(j: integer; n: edges): edges;var e: edges;begin e:= n; while (e<>nil)and(e^.toward^.id<>j) do e:= e^.next; find_edge:= eend;procedure new_edge(i,j,len: integer; var g: vertices);var vi,vj: vertices; eij: edges;begin vi:= find_vertex(i,g); if vi = nil then begin g:= new_vertex(i,g); vi:= g end; vj:= find_vertex(j,g); if vj = nil then begin g:= new_vertex(j,g); vj:= g end; eij:= find_edge(j,vi^.incidence); if eij = nil then begin new(eij); eij^.from:= vi; eij^.toward:= vj; eij^.len:= len; eij^.next:= vi^.incidence; vi^.incidence:= eij endend;procedure enqueue(v: vertices; var q,h: ptr_edges);var e: edges; pe: ptr_edges;begin e:= v^.incidence; while e<>nil do begin new(pe); pe^.e:= e; pe^.next:= nil; if q = nil then h:= pe else q^.next:= pe; q:= pe; e:= e^.next endend;procedure print_vertices(g: vertices);var v: vertices;begin v:= g; while v<>nil do begin writeln(source_id,' -> ',v^.id,' : ',v^.dist); v:= v^.next endend;procedure dispose_edges(n: edges);var e,e_next: edges;begin e:= n; while e<>nil do begin e_next:= e^.next; dispose(e); e:= e_next endend;procedure dispose_vertices(g: vertices);var v,v_next: vertices;begin v:= g; while v<>nil do begin v_next:= v^.next; dispose_edges(v^.incidence); dispose(v); v:= v_next; end;end;begin assign(f,'in'); reset(f); readln(f,source_id); {в первой строке записана начальная вершина} g:= nil; while not eof(f) do begin readln(f,i,j,len); {граф задан списком ребер: от, до, длина} new_edge(i,j,len,g); new_edge(j,i,len,g); end; source:= find_vertex(source_id,g); source^.dist:= 0; queue:= nil; head:= nil; enqueue(source,queue,head); while head<>nil do begin with head^.e^ do if from^.dist+len < toward^.dist then begin toward^.dist:= from^.dist + len; enqueue(toward,queue,head); end; next_head:= head ^.next; dispose(head); head:= next_head end; print_vertices(g); dispose_vertices(g);end.
a and b shr c mod a + c * a shl - b div aне меняют порядок выполнения операций?
program prog;var a: byte;procedure p1; function f: boolean; var a: byte; begin ... end; var a: byte; begin ... end;procedure p2;var a: byte; begin ... end;
unit A; unit C; unit F; interface interface interface uses C,D; uses D,F; var f; var a; var c; implementationimplementation implementation uses A; uses F; uses B; var ff; var aa; var cc; end;end; end;unit B; unit D; interface interface uses C; var d; var b; implementationimplementation uses B; uses D; var dd; var bb; end; end;
{b: char; p: ^shortint}b:= ‘Б’;p:= addr(b);a:= p^;
a: db: a c fc: dd: h gf: d
function f(const a:byte; var s:real; t:boolean):real;являются неправильными с точки зрения компилятора языка Pascal?
{s: string; i,k,t: byte}res:= ''; t:= length(s);if i > t then i:= t+1;for j:= 1 to i-1 do res:= res + s[j];for j:= i+k-1 to t do res:= res + s[j];
(a+b)*(c*d-k)-((m+n)/s*(t+y)*(z-x))
1) procedure step(v,k: byte; r: longint);var j: byte;begin if r < min then if k = N-1 then min:= r else for j:= 1 to N do if (sm[v,j]<>0)and(mark[j]=0) then begin mark[j]:= 1; step(j,k+1,r+sm[v,j]); mark[j]:= 0 end;end;2) for i:= 1 to N-1 dobeginfor x:= 1 to N doif (sm[last,x]<>0)and(not done[x])then dist[x]:= min(dist[x],dist[last]+sm[last,x]);min_dist:= MaxLongInt;for x:= 1 to N doif (not done[x])and(min>dist[x])then begin min_dist:= dist[x];last:= x; end;done[last]:= true;end;3)while head<>nil do begin with head^.e^ do if from^.dist+len < toward^.dist then begin toward^.dist:= from^.dist + len; enqueue(toward,queue,head); end; next_head:= head ^.next; dispose(head); head:= next_head end;4) procedure infix(var p: ukaz);begin read(c); case c of '(' : begin new(p); infix(p^.left) end; '+','-',*','/' : begin p^.symbol:= c; infix(p^.right) end; ')' : {ничего не делаем}; else begin p^.symbol:= c; p^.right:= nil; p^.left:= nil; end; end;end;
a + b or c shl a * c - a mod b > aне меняет порядок выполнения операций?
for i:= 1 to N do set_res[i]:= set1[i] or set2[i]
readln(f,s,k); {s: string[22], k:byte =0}
type data = record day: 1..31; month: 1..12; year: 1900.. 2100; end; employee = record name: string[20]; date_entering: data; case trade_union: boolean of true: (date_enter: data; leader: boolean); false: (manager: boolean); end;
var a: integer; r1: record a: byte; ... end; r2: record a: shortint; ... end;begin a:= 0; with r1 do begin r2.a:= -10; with r2 do begin a:= 100; r1.a:= -a; end end; a:= 100;end.
function C: boolean; forward;function D: boolean; forward;procedure A; begin x:= c(x); y:= d(y); end;function B: boolean; begin x:= c(x); end;function C; begin z:= c(z); end;function D; begin z:= d(z); end;
fib1 = 1;fib2 = 1;fibn = fibn-1+ fibn-2, для всех n>2.
{type ssylka = ^spisok; spisok = record znach: integer; next,prev: ssylka end;var head,p: ssylka;}new(head);read(f,head^.znach);head^.prev:= nil;p:= head;while not eof(f) do begin new(p^.next); read(f,p^.next^.znach); [???]; end;p^.next:= nil;p:= tail;
a b a cb cc hf d
const nnn=10000;type s1 = ^s2; s2 = record n,k,v: integer; next: s1; end;var f: text; head,p,q: s1; x,i,kr,vr,nxt,kol_ver: integer; a: array[1..nnn] of integer;begin assign(f,'in'); reset(f); readln(f,kol_ver); new(head); with head^ do readln(f,n,k,v); head^.next:= nil; while not eof(f) do begin new(q); with q^ do readln(f,n,k,v); q^.next:= nil; if q^.v <= head^.v then begin q^.next:= head; head:= q; continue end; p:= head; while p^.next<>nil do begin if q^.v > p^.next^.v then p:= p^.next else begin q^.next:= p^.next; p^.next:= q; break; end; end; if p^.next = nil then p^.next:= q; end; close(f);p:=head;while p<>nil do beginwrite(p^.v,' '); p:=p^.next;end;writeln('*'); for i:= 1 to kol_ver do a[i]:= 0; kr:= 0; vr:= 0; nxt:= 0; p:= head; while (p^.next <> nil)and(kr<kol_ver)do with p^ do begin if a[n]=0 then if a[k]=0 then begin inc(kr); inc(vr,v); inc(nxt); a[n]:= nxt; a[k]:= nxt; end else begin a[n]:= a[k]; inc(vr,v); end else if a[k]=0 then begin a[k]:= a[n]; inc(vr,v); end else if a[n]<>a[k] then begin x:= a[k]; for i:= 1 to kol_ver do if a[i]=x then a[i]:=a[n]; inc(vr,v) end; p:= next end; writeln(vr)end.
unit A; unit C; unit F; interface interface interface uses C,D; uses D,F; var f; var a; var c; implementationimplementation implementation uses A; uses F; uses B; var ff; var aa; var cc; end;end; end;unit B; unit D; interface interface uses C; var d; var b; implementationimplementation uses B; uses D; var dd; var bb; end; end;
readln(f,s,k); {s: string[22], k:byte =0}
z:= 0;if a>10 then if a>100 then if a>1000 then z:= 1 else z:= -1 else z:= 10;
a b c d fa 0 5 0 7 0b 5 0 8 4 0c 0 8 0 6 0d 7 4 6 0 3f 0 0 0 3 0
{type ssylka = ^spisok; spisok = record znach: array[1..1000]of integer; next,prev: ssylka end;var head,p: ssylka;}p:= head^.next^.next;p^.prev^.next:= p^.next;p^.next:= p^.next^.next;p^.prev^.next^.next:= p;p^.next^.prev^.prev:= p^.prev; [???];p^.prev:= p^.prev^.next;
function C: boolean; forward;function D: boolean; forward;procedure A; begin x:= c(x); y:= d(y); end;function B: boolean; begin a; end;function C; begin z:= b(z); end;function D; begin z:= b(z); end;
(Сnk = n!/k!(n-k)!)определяемый следующим образом:
Сnk = 0, если k > n;Сnk = 1, если k = 0 или k = n;Сnk = Сn-1k + Сn-1k-1 в остальных случаях.
for i:= 1 to N do set_res[i]:= (set1[i] or set2[i])and not set2[i]
a: d f gb: dd: c fg: hh: f
rewrite(f);for c:= '0' to '9' do write(f,c); {c: char}seek(f,5);read(f,c);write(f,c);seek(f,3);truncate(f);seek(f,9);write(f,c);
program prog;var a: byte;procedure p1; var a: byte; begin ... end;procedure p2; function f: boolean; var a: byte; begin ... end; var a: byte; begin ... end;
a: b db: d ff: c d gd: h gh: g
a: b db: d ff: c d gd: h gh: g
var a: longint; r1: record a: word; ... end; r2: record a: integer; ... end;begin a:= 0; with r1 do begin a:= 1000; with r2 do begin a:= 1000; r1.a:= -a; end; r2.a:= -100; end; a:= 100;end.
var a: byte;proc p1(k: byte);proc p2(var t: byte); begin t:= t*2 end;var a: byte; begin a:= 1; k:= 5; p2(a); end;begin a:= 10; p1(a);end.
a b c d fa 0 3 10 0 0b 3 0 5 0 0c 10 5 0 2 4d 0 0 2 0 2f 0 0 4 2 0
{массив а хранит веса всех предметов, в порядке их ввода, half - "большая" половина суммы всех весов, dif - отклонение текущей найденной суммы от half}procedure rec(k: byte; sum: longint; var dif: longint);var i: byte;begin if sum+a[k]<=half then for i:= k+1 to n do rec(i,sum+a[k],dif) else if half-sum<dif then begin dif:= half-sum; if dif<2 then out(dif){печать и завершение} endend;