调用随机函数产生10个互不相同的随机整数(0≤x≤40),放入集合中并一起输出(5个一行)。

提示:随机函数使用randomize;{初始化}m:=random(n);{n,m都是整数,那么0≤m≤n-1}

var a:set of 0..40;
      i,m,n:integer;
begin
   a:=[];
   randomize;
   while n<10 do
       begin
      m:=random(41);
      if not(m in a) then
        begin
          a:=a+[m];   n:=n+1;
       end;
    end;
   n:=0;
   for i:=0 to 40 do
      if i in a then
         begin
           write(i:4);    n:=n+1;
           if n=0 then writeln;
         end;
    readln;
end.

输入一个大写字母字符串,找出未在此串中出现的所有大写字母。

var
st:string;
a:set of 'A'..'Z';
i,leng:longint;
ch:char;
begin
    for ch:='A' to 'Z' do a:=a+[ch];

    write('Enter Your String : ');
    readln(st);
    leng:=length(st);
    for i:=1 to leng do
        begin
            if st[i] in a then a:=a-[st[i]];
        end;
    for ch:='A' to 'Z' do
        if ch in a then write(ch:4);
readln;
end.
{As there is no test in 7.2
I decided to use this program to do some test
Also can be used as a review file.
Codes below.
}
type type1=(A,B);
var
x:record
    a:integer;
    b:type1;
    end;
y:record
    c:type1;
    d:record
        e:type1;
        f:integer;
        end;
    end;
begin
 with x do a:=100;
 writeln(x.a);
 with x do
    begin
        a:=10;
    end;
writeln(x.a);
with x do
    begin
        a:=1;
        writeln(a);
    end;
with y do
    with d do
        f:=20;
writeln(y.d.f);
with y,d do
    f:=200;
writeln(y.d.f);
readln;
end.

Pascal:集合记录与文件,习题
https://Mundnaity.moe/post/pascal_chap7_ex
作者
申酉和风
发布于
2016-10-23
许可协议