1.
var
x:longint;
flag: boolean;
begin
read(x);
flag := false;
if (x mod 4 = 0) and (x mod 100 <> 0) then flag := true;
if x mod 400 = 0 then flag := true;
if flag then writeln(‘leap year!’)
else writeln(‘not a leap year!’);
end.
输入:1234
输出
输出:not a leap year!
2.
var
f: array[1..100, 1..100] of longint;
cnt: longint;
i, j, n, t, x, y, ans: longint;
begin
read(n);
x := 1;
y := 0;
for i := 1 to n do
begin
for j := 1 to n*2-i+1 do
begin
inc(y);
inc(cnt);
f[x, y] := cnt;
end;
for j := 1 to n*2-i do
begin
inc(x);
inc(cnt);
f[x, y] := cnt;
end;
for j := 1 to n*2-i do
begin
dec(y);
dec(cnt);
f[x, y] := cnt;
end;
for j := 1 to n*2-i-1 do
begin
dec(x);
dec(cnt);
f[x, y] := cnt;
end;
end;
read(t);
ans := 0;
for i := 1 to n*2 do
ans := ans + f[t, i];
writeln(ans);
end.
输入:3 2
输出:27
3.
var
t: longint;
function f(x:longint): longint;
begin
if x = 0 then exit(0)
else if x mod 2 = 0 then exit(2 + f(x-1))
else exit(1 + f(x-1));
end;
begin
read(t);
writeln(f(t));
end.
输入:2014
输出:3021
4.
type arr=array[0..100000]of longint;
var
c, q, d, e, ans: arr;
n, i: longint;
procedure merge(a, b: longint);
var
mid, i, j, p: longint;
begin
mid := (a+b) div 2;
if a < mid then merge(a, mid);
if mid+1 < b then merge(mid+1, b);
p:=0; i:=a; j:=mid+1;
while (i <= mid) and (j <= b) do
begin
if c[i] >= c[j] then
begin
p := p+1; d[p] := c[i]; e[p] := q[i]; i := i+1;
end
else
begin
p := p+1; d[p] := c[j]; e[p] := q[j];
j := j+1; inc(ans[e[p]], mid-i+1);
end;
end;
while (i <= mid) and (j > b) do
begin
p := p+1; d[p] := c[i]; e[p] := q[i]; i := i+1;
end;
while (i > mid) and (j <= b) do
begin
p := p+1; d[p] := c[j]; e[p] := q[j]; j := j+1;
end;
for i := a to b do
begin
c[i] := d[i-a+1]; q[i] := e[i-a+1];
end;
end;
begin
readln(n);
for i := 1 to n do
begin
read(c[i]); q[i] := i;
end;
merge(1, n);
for i := 1 to n-1 do
write(ans[i], ’,’);
writeln(ans[n]);
end.
输入
5
4 3 1 2 5
输出:0,0,0,1,4