1.
var
n,i,temp,sum:integer;
a :array[1..100] of integer;
begin
readln(n);
for i:=1 to n do
read(a[i]);
for i:=1 to n-1 do
if a[i]>a[i+1] then
begin
temp := a[i];
a[i] := a[i+1];
a[i+1] := temp;
end;
for i:=n downto 2 do
if a[i]<a[i-1] then
begin
temp := a[i];
a[i] := a[i-1];
a[i-1] := temp;
end;
sum := 0;
for i:=2 to n-1 do
inc(sum,a[i]);
writeln(sum div (n-2));
end.
输入: 8
40 70 50 70 20 40 10 30
输出:41
2.
var
n,i,ans:integer;
function gcd(a,b :integer) : integer;
begin
if a mod b=0
then gcd :=0;
else gcd := gcd(b,a mod b);
end;
begin
readln(n);
ans := 0;
for i:=1 to n do
if gcd(n,i)=i
then ans := ans + 1;
writeln(ans);
end.
输入:120
输出:16
3.
var
data : array[1..20] of integer;
n,i,h,ans: integer;
procedure merge;
begin
data[h-1] := data[h-1] + data[h];
dec(h);
inc(ans);
end;
begin
readln(n);
h := 1;
data[h] := 1;
ans := 0;
for i:=2 to n do
begin
inc(h);
data[h] := 1;
while (h>1) and (data[h]=data[h-1]) do
merge;
end;
writeln(ans);
end.
(1)
输入:8
(2)
输入:2012
输出:7 2004
4.
var
left, right, father:array[1..20] of integer;
sl, s2, s3:string;
n,ana :integer;
procedure check(x:integer);
begin
if left[x]>0 then check(left[x));
s3 := s3 + sl[x];
if right[x]>0 then check(right[x]);
end;
procedure calc(x,dep :integer);
begin
ans:= ans + dep*(ord(sl[x])-ord('A')+1);
if left[x] > 0 then calc(left[x],dep+l);
if right[x]> 0 then calc(right[x),dep+l);
end;
procedure dfs(x,th :integer);
begin
if th = n+1 then
begin
s3 :='';
check(1);
if s2=s3 then
begin
ans := 0;
calc(1,1);
writeln(ans);
end;
exit;
end;
if (left[x]=0) and (right[x]=0) then
begin
left[x) := th;
father[th] := x;
dfs(th, th+1);
father[th] := 0;
left[x] := 0;
end;
if right[x] = 0 then
begin
right[x] := th;
father[th] := X;
dfs(th, th+1);
father[th] := 0;
right[x] := 0;
end;
if (father[x] > 0) then
dfs(father[x],th);
end;
begin
readln(s1);
readln(s2);
n := length(s1);
fillchar(left,sizeof(left),0);
fillchar(right,sizeof(right),0);
fillcahr(father,sizeof(father),0);
dfs(1,2);
end.
输入:
ABCDEF
BCAEDF
输出:55