Page 57 - C:\Users\Admin\Desktop\Sach mem upweb\
P. 57

100 Problems & Solutions                                                Trang 57


                      Var st:string[10];
                             dem,M:longInt;
                      Begin
                        dem:=0;
                        M:=1;
                        Repeat
                           str(M,st);
                           dem := dem+length(st);
                           inc(M);
                        Until dem >= NN;
                        chuso := st[length(st) - (dem - NN)]
                        (*-------------------------------------*)
                        BEGIN
                            clrscr;;
                            write('Nhap k:');
                            Readln(k);
                            Writeln('Chu so thu', k,'cua day vo han cac so nguyen khong am');
                            write('123456789101112... la:', chu so(k));
                            Readln;
                      END.
                      Cách giải khác:
                      var n, Result: LongInt;

                      procedure ReadInput;
                      begin
                        Write('Ban hay nhap so K: '); Readln(n);
                      end;

                      procedure Solution;
                      var
                        i, Sum, Num, Digits: LongInt;
                      begin
                        Sum := 9; Num := 1; Digits := 1;
                        while Sum < n do
                        begin
                          Num := Num * 10; Inc(Digits);
                          Inc(Sum, Num * 9 * Digits);
                        end;
                        Dec(Sum, Num * 9 * Digits); Dec(n, Sum);
                        Num := Num + (n - 1) div Digits;
                        n := (n - 1) mod Digits + 1;
                        for i := 1 to Digits - n do Num := Num div 10;
                        Result := Num mod 10;
                      end;

                      procedure WriteOutput;
                      begin
                        Writeln('Chu so can tim la: ', Result);
                        Readln;
                      end;
                      begin



                      Tin học & Nhà trường                                       100 Đề Toán - Tin học
   52   53   54   55   56   57   58   59   60   61   62