1.
var
a, b, i, tot, c1, c2: integer;
begin
readln(a, b);
tot := 0;
for i := a to b do
begin
c1 := i div 10;
c2 := i mod 10;
if (c1 + c2) mod 3 = 0 then
inc(tot);
end;
writeln(tot);
end.
输入:7 31
输出:8
2.
var
n, m: integer;
function fun(n, minNum, maxNum: integer): integer;
var tot, i: integer;
begin
if n = 0 then
exit(1);
tot := 0;
for i := minNum to maxNum do
tot := tot + fun(n - 1, i + 1, maxNum);
exit(tot);
end;
begin
readln(n, m);
writeln(fun(m, 1, n));
end.
输入:6 3
输出:20
3.
const
SIZE = 100;
var
dict: array [1..SIZE] of string;
rank, ind: array [1..SIZE] of integer;
i, j, n, tmp: integer;
begin
readln(n);
for i := 1 to n do
begin
rank[i] := i;
ind[i] := i;
readln(dict[i]);
end;
for i := 1 to n - 1 do
for j := 1 to n - i do
if dict[ind[j]] > dict[ind[j + 1]] then
begin
tmp := ind[j];
ind[j] := ind[j + 1];
ind[j + 1] := tmp;
end;
for i := 1 to n do
rank[ind[i]] := i;
for i := 1 to n do
write(rank[i], ' ');
writeln;
end.
输入:
7
aaa
aba
bbb
aaa
aaa
ccc
aa
输出:2 5 6 3 4 7 1
4.
const
SIZE = 100;
var
alive: array [1..SIZE] of integer;
n, m, num, i, j: integer;
function next(num: integer): integer;
begin
repeat
inc(num);
if num > n then
num := 1;
until alive[num] <> 0;
exit(num);
end;
begin
read(n, m);
for i := 1 to n do
alive[i] := 1;
num := 1;
for i := 1 to n do
begin
for j := 1 to m - 1 do
num := next(num);
write(num, ' ');
alive[num] := 0;
if i < n then
num := next(num);
end;
writeln;
end.
输入:11 3
输出:3 6 9 1 5 10 4 11 8 2 7