回 帖 发 新 帖 刷新版面

主题:[讨论]帮忙改错!!!

牛的"非拨拉机"数列:
输入前两个数,得出后面的前500个数,把它们连起来,中间没有空格.
如:输入1 1 数列为1123581321……,求第K位数列中的数字.

这是我编的,是把它们全求出来,放在一个数组里,每位放一个数字,然后输出,可是有错误,请大家帮我查查错,谢谢!!!
var
   a,b,c,r,i,j,z,k,q:longint;
   s,s1,s2:string;
   x:array[1..500] of longint;
begin
     read(a,b,k);'A,B为输入的首两位,K为要输出的第K位
     q:=0;'一个数字放在数组中的第Q位
     str(a,s);'S是要求A的位数方便的字符串变量,与S1,S2意义相同
     j:=a;'为使A的值计算后不变,用的一个代替变量
     r:=length(s);
     r:=r+1;'是求数组中位数与P相减(算出来的,可能错)的变量
     repeat
           q:=q+1;
           x[r-q]:=j mod 10;     '取数的每一位,但因第一个取的是个位,所以要用
                                  R和P来计算每一次取的数在数组中的第几位(就
                                  是这里有可能有错)
           j:=j div 10;
     until (j=0);
     z:=b;
     str(b,s1);
     r:=length(s1);
     r:=r+1;
     repeat
           q:=q+1;
           x[r-q]:=z mod 10;
           z:=z div 10;
     until (z=0);
     for i:=3 to 500 do
     begin
          c:=a+b;
          j:=c;
          str(c,s2);                         '计算后面的数,并按上面的方法放置
          r:=length(s2);
          r:=r+1;
          repeat
                q:=q+1;
                x[r-q]:=j mod 10;
                j:=j div 10;
          until (j=0);
          b:=a;
          c:=b;
     end;
     writeln(x[k]);                     '输出第K位
end.
[em18]

回复列表 (共17个回复)

11 楼

program gai;
var
        a,b,c,r,j,k,q:longint;
        s:string;
        x:array[1..500] of longint;
begin
        readln(a,b,k);
        q:=0;
        str(a,s);
        j:=a;
        r:=length(s);
        repeat
                x[r-q]:=j mod 10;
                j:=j div 10;
                inc(q);
        until (j=0);
        j:=b;
        str(b,s);
        r:=r+length(s);
        q:=0;
        repeat
                x[r-q]:=j mod 10;
                j:=j div 10;
                inc(q);
        until (j=0);
        if k<=r then writeln(x[k])
                else begin
                        while r<k do
                                begin
                                        c:=a+b;
                                        j:=c;
                                        str(c,s);
                                        r:=r+length(s);
                                        q:=0;
                                        repeat
                                                x[r-q]:=j mod 10;
                                                j:=j div 10;
                                                inc(q);
                                        until (j=0);
                                        a:=b;
                                        b:=c;
                                end;
                        end;
        writeln(x[k]);
        readln;
end.

12 楼

program gai;
var
        a,b,c,r,j,k,q:longint;
        s:string;
        x:array[1..500] of longint;
begin
        readln(a,b,k);
        q:=0;
        str(a,s);
        j:=a;
        r:=length(s);
        repeat
                x[r-q]:=j mod 10;
                j:=j div 10;
                inc(q);
        until (j=0);
        j:=b;
        str(b,s);
        r:=r+length(s);
        q:=0;
        repeat
                x[r-q]:=j mod 10;
                j:=j div 10;
                inc(q);
        until (j=0);
        if k<=r then writeln(x[k])
                else begin
                        while r<k do
                                begin
                                        c:=a+b;
                                        j:=c;
                                        str(c,s);
                                        r:=r+length(s);
                                        q:=0;
                                        repeat
                                                x[r-q]:=j mod 10;
                                                j:=j div 10;
                                                inc(q);
                                        until (j=0);
                                        a:=b;
                                        b:=c;
                                end;
                        end;
        writeln(x[k]);
        readln;
end.

13 楼

program gai;
var
        a,b,c,r,j,k,q:longint;
        s:string;
        x:array[1..500] of longint;
begin
        readln(a,b,k);
        q:=0;
        str(a,s);
        j:=a;
        r:=length(s);
        repeat
                x[r-q]:=j mod 10;
                j:=j div 10;
                inc(q);
        until (j=0);
        j:=b;
        str(b,s);
        r:=r+length(s);
        q:=0;
        repeat
                x[r-q]:=j mod 10;
                j:=j div 10;
                inc(q);
        until (j=0);
        if k<=r then writeln(x[k])
                else begin
                        while r<k do
                                begin
                                        c:=a+b;
                                        j:=c;
                                        str(c,s);
                                        r:=r+length(s);
                                        q:=0;
                                        repeat
                                                x[r-q]:=j mod 10;
                                                j:=j div 10;
                                                inc(q);
                                        until (j=0);
                                        a:=b;
                                        b:=c;
                                end;
                        end;
        writeln(x[k]);
        readln;
end.
前几天就编好了,就是没机会上网,让你久等了

14 楼

测试

15 楼

忘了还有下一页,我还以为系统出错了,对不起,弄得满屏都是

16 楼


谢谢
很谢谢
非常谢谢
很非常谢谢
非常非常谢谢
很非常非常谢谢
非常非常非常谢谢
    .
    .
    .
    .
    .

17 楼

不用,共同促进

我来回复

您尚未登录,请登录后再回复。点此登录或注册