扫一扫,加我们为好友有惊喜哦~
-->

核心课程
开班动态
专题服务

您当前所在位置:首页 > 中心动态 >>
[常州软件培训]Pascal学习笔记(四)

 东方博宜教育Pascal习题复习大纲(四)

复习要求:认真复习本提纲中的习题,做到每道题都能自己写出答案

1188: 【基础】高精度加法

思路:

第一步:采用两个string将两个大数字读入

第二步:将两个string倒过来放到数组中

第三步:将两个数组对应位的数相加,和放到第三个数组中,但判断和 >= 10,则mod 10结果留下,div 10的结果加到下一位

注意:两个数组最后一位相加时可能要进1,也就是3位数 + 3位数可能得到4位数

var s1,s2:string;

    a,b,c:array[1..241] of integer;

    i,j,t,len:integer;

begin

   readln(s1);

   readln(s2);

 

   for i := 1 to length(s1) do

     a[i] := ord(s1[length(s1) - i + 1]) - 48;

 

   for i := 1 to length(s2) do

     b[i] := ord(s2[length(s2) - i + 1]) - 48;

 

   len := length(s1);

   if length(s2) > length(s1) then

     len := length(s2);

 

   t := 0;

   for i := 1 to len do

   begin

     c[i] := a[i] + b[i] + t;

     t := c[i] div 10;

     c[i] := c[i] mod 10;

   end;

   if t <> 0 then

   write(t);

 

   for i := len downto 1 do

     write(c[i]);

   writeln; readln;

end.

1123: 【入门】数组元素的排序

思路:n个数,比较n-1轮,每轮从第一个数比较到n - i + 1这个数!

      每轮比较中,如果前面的数比后面的数大,则交换!

var a:array[1..10] of integer;

    i,j,n,t:integer;

begin

    readln(n);

    for i := 1 to n do

       read(a[i]);

 

    for i := 1 to n - 1 do

      for j := 1 to n - i do

      begin

         if a[j] > a[j + 1] then

         begin

           t := a[j];

           a[j] := a[j + 1];

           a[j + 1] := t;

         end;

      end;

 

    for i := 1 to n do

      if i = n then

         writeln(a[i])

      else write(a[i],' ');

 

    readln;    readln;

end.


 

 

1040: 【入门】打印字母塔

var i,n,j:integer;

c:char;

begin

    readln(n);

    for i:=1 to n do

    begin

        for j:=1 to n-i do

        begin

           write(' ');

        end;

        for j:=i downto 2 do

        begin

            c:=chr(j+ord('A')-1);

            write(c);

        end;

        for j:=1 to i do

        begin

            c:=chr(j+ord('A')-1);

            write(c);

        end;

        writeln;

    end;

    readln;

end.

 

1085: 【入门】百钱百鸡问题

var i,j,x,y,t,m,n:integer;

begin

    for i:=1 to 100 div 5 do

    begin

        x:=100 - i * 5;

 

        for j:=1 to x div 3 do

        begin

            y:=x - j * 3;

 

      if (y > 0) and (i + j + y * 3 = 100)  then

              writeln(i,' ',j,' ',y * 3);

        end;

    end;

    readln;

 end.

 

 

1292: 【入门】歌唱比赛评分

var a:array[1..10]of integer;

    i,n,max,min,s:integer;

    r:real;

begin

    readln(n);

 

    for i := 1 to n do

      read(a[i]);

    readln;

 

    min := a[1];

    max := a[1];

    for i:= 2 to n do

    begin

        if a[i] > max then

          max:=a[i];

        if a[i] < min then

          min:=a[i];

    end;

 

    s := 0;

    for i := 1 to n do

    begin

        s:=s+a[i];

    end;

    r:=(s-max-min)/(n-2);

    writeln(r:0:2);

    readln;

end.

 


 

题目:将二进制转八进制

从最低位开始,每三位一个单元,最前面如果不够三位,补充0,计算每个三位对应的十进制,连在一起就可以!

1001110-> 001 001 110->116

第一步:写函数将一个三位的2进制数转成十进制

第二步:读入一个字符串,判断前面要补几个0

第三步:每3位一个单元,调用函数转十进制

function num(var s:string):integer;

  var r:integer;

begin

   r := (ord(s[1]) - 48) * 4 + (ord(s[2]) - 48) * 2 + (ord(s[3]) - 48);

   num := r;

end;

 

var s,t,r,m:string;

    x,i:integer;

begin

    readln(s);

 

    if length(s) mod 3 = 1 then s := '00' + s

    else if length(s) mod 3 = 2 then s := '0' + s;

 

    t := '';

    r := '';

    for i := 1 to length(s) do

    begin

       t := t + s[i];

 

       if length(t) = 3 then

       begin

          x := num(t);

          str(x,m);

          r := r + m;

          t := '';

       end;

    end;

    writeln(r);  readln;

end.

题目:将一个十六进制的数,转换成二进制的数!(高精度转换)

思路:将每一个十六进制的数,转换成四位的对应的二进制(不够补0),连在一起,删除最前面的0

第一步:写函数,计算一个十六进制数对应的二进制!

判断是否是四位,不满四位补0

function num (var c:char):string;

  var i,t,x:integer;

  s,j:string;

begin

   j:='';

   if (c >='0') and (c <= '9') then

     t:=ord(c) - 48

   else if (c >='A') and (c <='F') then

     t:=ord(c) - 55;

 

   while t <> 0 do

   begin

       x:=t mod 2;

       t:=t div 2;

       str(x,s);

       j:=s+j;

   end;

 

   if length(j) = 3 then

     j:='0' + j

   else if length(j) = 2  then

     j:='00' + j

   else if length(j) = 1  then

     j:='000'+ j;

 

   num:=j;

end;

 

var s,x,r:string;

    i:integer;

begin

    r:='';

    x:='';

    readln(s);

    for i:=1 to length(s) do

    begin

        x:=num(s[i]);

        r:=r+x;

    end;

    while r[1] = '0' do

      delete(r,1,1);

    writeln(r);

    readln;

end.

 

1089: 【入门】那些4位数

var i,j,k,n:integer;

begin

    for i:=1 to 4 do

      for j:=1 to 4 do

        for k:=1 to 4 do

          for n:=1 to 4 do

          begin

              writeln(i*1000+j*100+k*10+n);

          end;

 

    readln;

end.

 

1262: 【入门】统计个数

var a:array[1..20]of integer;

    i,t,x,y:integer;

begin

    y:=0;

    t:=0;

    x:=0;

    for i:=1 to 20 do

    begin

        readln(a[i]);

    end;

 

    for i:=1 to 20 do

    begin

        if a[i] > 0 then

          y:=y+1

        else if a[i] = 0 then

          x:=x+1

        else if a[i] < 0 then

          t:=t+1;

    end;

    writeln(y,' ',x,' ',t);

    readln;

end.

 

1045: 【入门】求出100以内的全部素数,并按每行五个数显示

function sushu (var n:integer):boolean;

var i:integer;

f:boolean;

begin

    f:=true;

 

    for i:=2 to trunc(sqrt(n)) do

      if n mod i = 0 then

      begin

          f:=false;

          break;

      end;

 

    if n <= 1 then

      f:=false;

 

    sushu:=f;

end;

 

var i,s,t:integer;

f:boolean;

begin

    s:=0;

    for i:=1 to 100 do

    begin

        t:=i;

        f:=sushu(t);

        if f=true then

        begin

            s:=s+1;

            if s mod 5 = 0 then

            writeln(t)

            else

            write(t,' ');

        end;

    end;

    readln;   end.


1108: 【入门】字符图形7-星号菱形

var i,j,n:integer;

begin

    readln(n);

    n:=n+1;

    for i:= 1 to n do

    begin

        for j:= 1 to n-i do

        begin

            write(' ');

        end;

       

        for j:= 1 to 2*i-1 do

        begin

            write('*');

        end;

        writeln;     

    end;

   

    for i:=2 to n do

    begin

        for j:= 1 to i-1 do

        begin

            write(' ');        

        end;

       

        for j:= 1 to (n-i+1) * 2 - 1 do

        begin

            write('*');        

        end;

        writeln;

    end;

    readln;

end.

 

1085: 【入门】百钱百鸡问题

var a,b,c,t,s,i,j:integer;

begin

    for i:=1 to 100 div 5 do

    begin

        t:=100 - 5 * i;

        for j:=1 to t div 3 do

        begin

            s:=t - j * 3;

            if s*3 + i + j = 100 then

              writeln(i,' ',j,' ',s*3); 

        end;

    end;

    readln;

end.

 

1024: 【入门】打印小写字母表

var i:integer;

c:char;

begin

    for i:= 1 to 26 do

    begin

        c:=chr(i+96);

        write(c);

        if i=13 then

          writeln;

    end;

    writeln;

    for i:=26 downto 1 do

    begin

       c:=chr(i+96);

       write (c);

       if i=14 then

       writeln;

    end;

    readln;

end.

 

1036: 【入门】统计字符的个数

var s:string;

    i,t,n,b,q:integer;

begin

    readln(s);

    n:=0;

    b:=0;

    q:=0;

 

    for i:=1 to length(s) do

    begin

        if (s[i] >='A') and (s[i] <='Z') then

        n:=n+1;

 

        if (s[i] >='a') and (s[i] <='z') then

        b:=b+1;

 

        if (s[i] >='0') and (s[i] <='9') then

        q:=q+1;

    end;

    writeln(n,' ',b,' ',q);

    readln;

end.

 

1132: 【入门】词组缩写

var s,t,n:string;

i,x:integer;

begin

    readln(t);

    t:=' '+t;

    s:='';

    for i:=2 to length(t) do

    begin

 

        if (t[i] <> ' ') and (t[i - 1] = ' ') then

        begin

          if (t[i] >='a') and (t[i] <='z') then

          begin

              x:=ord(t[i]) - 32;

              t[i] := chr(x);

          end;

          s:=s+t[i];

        end;

    end;

    writeln(s);

    readln;

end.

 

1237: 【入门】调换位置

var s,s1,s2:string;

p:integer;

begin

    readln(s);

    p:= pos(',',s);

 

    s1:= copy(s,1,p-1);

    s2:= copy(s,p+1,length(s)-p);

 

    writeln(s2,',',s1);

    readln;

end.

 

 

1575: 【入门】求各位数字之和

var n,m,x,i:longint; s,t:string;c:integer;

begin

    readln(n);

    x:=0;

    str(n,s);

    for i:=1 to length(s) do

    begin

        t:=s[i];

        val(t,m,c);

        x:=m+x;

    end;

    writeln(x);

    readln;

end.

 

1238: 【入门】统计单词个数

var s,w:string;

    i,c:integer;

begin

    readln(s);

    c:=0;

    s:=s+' ';

    w:='';

 

    for i:=1 to length(s) do

    begin

        if s[i] <> ' ' then

        begin

            w:=w+s[i];

            if s[i+1] =' ' then

            begin

                   c:=c+1;

                   w:='';

            end;

        end;

    end;

    writeln(c);

    readln;

end.

 

1047: 【入门】正整数N转换成一个二进制数

var n,t:integer;

s,x:string;

begin

    readln(n);

    s:='';

    while n <> 0 do

    begin

        t:=n mod 2;

        str(t,x);

        s:=x + s;

        n:=n div 2;

    end;

    writeln(s);

    readln;

end.

 

 

1059: 【基础】隐藏的最大整数

var s,n:string;

i,c:integer;

m,t,j:longint;

begin

    readln(s);

    n:='';

    m:=0;

    j:=0;

 

    for i:=1 to length(s) do

    begin

        if (s[i]>='0')  and  (s[i]<='9') then

        begin

            n:=n+s[i];

 

            if (s[i+1]<'0') or (s[i+1]>'9') then

            begin

                val(n,t,c);

                if t > m then

                begin

                    m:=t;

                    j:=i-length(n) + 1;

                end;

                n:='';

            end;

        end;

    end;

    writeln(j);

    readln;

end.

 

 

1075: 【基础】趣味填空

var s,y,z,n2,n1:string;

p,i,m1,m2,y2:longint;

f:boolean;

c:integer;

begin

    readln(s);

    f:=false;

    p:=pos('=',s);

    z:=copy(s,1,p-1);

    z:=copy(s,1,p-1);

    y:=copy(s,p+1,length(s));

    val(y,y2,c);

    for i:=1 to length(z)-1 do

    begin

        n1:=copy(z,1,i);

        n2:=copy(z,i+1,length(z));

        val(n1,m1,c);

        val(n2,m2,c);

 

        if m1 +m2 =y2 then

        begin

            writeln(m1,'+',m2,'=',y2);

            f:=true;

        end;

    end;

    if f=false then

    writeln('Impossible!');

 

    readln;

end.

 


 

 

1094: 【入门】求一个最小数

var i,x:longint; s:string; c:integer;

begin

    i:=17;

    while true do

    begin

        str(i div 10,s);

        s:='7'+s;

        val(s,x,c);

        if x=i*5 then

          break

        else

          i:=i+1;

    end;

    writeln(i);

    readln;

end.

 


精彩文章推荐
常州招聘【三维动画设计师】[2014-1-7]
【常州单片机培训】单片机:汇编语言入门[2013-11-23]
form表单的常见写法[2012-7-14]
JSP访问原理——东方博宜电脑课程[2012-7-9]
CRM系统需求——东方博宜电脑培训[2012-7-8]
static、final关键字——常州电脑培训[2012-6-26]
优化网站需要分析哪些数据[2012-4-26]
常州PS培训|Photoshop路径技巧[2011-11-11]


返回顶部