1.
program s401;
var p,q:array[0..5] of integer;
i,x,y:integer;
begin
y:=20;
for i:=0 to 4 do read(p[i]);
readln;
q[0]:=(p[0]+p[1])+(p[2]+p[3]+p[4]) div 7;
q[1]:=p[0]+p[1] div ((p[2]+p[3]) div p[4]);
q[2]:=p[0]*p[1] div p[2];
q[3]:=q[0]*q[1];
q[4]:=q[1]+q[2]+q[3];
x:=(q[0]+q[4]+2)-p[(q[3]+3) mod 4];
if (x>10) then
y:=y+(q[1]*100-q[3]) div (p[p[4] mod 3]*5)
else
y:=y+20+(q[2]*100-q[3]) div (p[p[4] mod 3]*5);
writeln(x,',',y);
end.
/*注:本例中,给定的输入数据可以避免分母为 0 或下标越界。
输入:6 6 5 5 3
输出:129,43
2.
program s402;
var a,b:integer;
x,y:^integer;
procedure fun(a,b:integer);
var k:integer;
begin
k:=a; a:=b; b:=k;
end;
begin
a:=3; b:=6;
x:=@a; y:=@b;
fun(x^,y^);
write('No.1:',a,',',b,' ');
fun(a,b);
writeln('No.2:',a,',',b);
end.
输出:No.1:3,6 No.2:3,6
3.
program S403;
var a1:array[1..50] of integer;
var i,j,t,t2,n,n2:integer;
begin
n:=50;
for i:=1 to n do a1[i]:=0;
n2:=round(sqrt(n));
for i:=2 to n2 do
if(a1[i]=0) then
begin
t2:=n div i;
for j:=2 to t2 do a1[i*j]:=1;
end;
t:=0;
for i:=2 to n do
if (a1[i]=0) then
begin
write(i:4); inc(t);
if(t mod 10=0) then writeln;
end;
writeln;
end.
输出: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
4.
program S404;
const n=12;
ch2:array[0..12] of char
=('q','A','S','O','R','T','E','X','A','M','P','L','E');
var k:integer;
ch:array[0..12] of char;
procedure shift(k,n:integer);
var v:char;
j:integer;
begin
v:=ch[k]; j:=k+k;
while (j<=n) do
begin
if (j<n) and (ord(ch[j])<ord(ch[j+1])) then inc(j);
if (ord(v)<ord(ch[j])) then
begin ch[j div 2]:=ch[j]; j:=j*2; end
else
exit;
ch[j div 2]:=v;
end;
end;
procedure hpsrt;
var k:integer;
tmp:char;
begin
for k:=n div 2 downto 1 do shift(k,n);
write('No.1: ');
for k:=1 to n do write(ch[k]);
writeln;
for k:=n downto 1 do
begin
tmp:=ch[1]; ch[1]:=ch[k]; ch[k]:=tmp;
shift(1,k-1);
end;
end;
begin
for k:=0 to n do ch[k]:=ch2[k];
hpsrt;
write('No.2: ');
for k:=1 to n do write(ch[k]);
writeln;
end.
输出:No.1: XTORSEAAMPLE
No.2: AAEELMOPRSTX