ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1150. Page Numbers

Would you like to tell me why I got WA using this source code?
Posted by lyj_george 6 Feb 2002 08:55
var
  tot : array [0..9] of longint;
  i : byte;
  zg : longint;
  n : string;
  r : longint;
  error : integer;
function cf(ll:byte) : longint;
var
  tt,ti : longint;
begin
  tt := 1;
  for ti := 1 to ll do
    tt := tt * 10;
  cf := tt;
end;
function change(aa,bb:byte) : longint;
var
  tstr : string;
  o : longint;
begin
  tstr := copy(n,aa,bb-aa+1);
  val(tstr,o,error);
  change := o;
end;

procedure solve(now:byte);
var
  k : byte;
  ttt : string;
begin
  str(now,ttt);
  for k := 1 to length(n) do begin
    if k = 1 then begin
          if ttt[1] < n[1] then tot[now] := tot[now] + cf(length(n)-
k);
          if ttt[1] = n[1] then tot[now] := tot[now] + change(2,length
(n)) + 1;
        end;
    if k = length(n) then begin
                  tot[now] := tot[now] + change(1,k-1);
                  if ttt[1] <= n[k] then inc(tot[now]);
                end;
    if (k>1) and (k<length(n)) then begin
      tot[now] := tot[now] + change(1,k-1) * cf(length(n) - k);
      if ttt[1] < n[k] then tot[now] := tot[now] + cf(length(n) - k);
      if ttt[1] = n[k] then tot[now] := tot[now] + change(k+1,length
(n))+1;
    end;
end;
end;
procedure out;
begin
  tot[0] := zg - tot[1] - tot[2] - tot[3] - tot[4] - tot[5]
            - tot[6] - tot[7] - tot[8] - tot[9];
  for i := 0 to 9 do
    writeln(tot[i]);
end;
begin
  readln(n);
  val(n,r,error);
  zg := 0;
  for i := 1 to length(n)-1 do
    zg := zg + 9 * cf(i-1) * i;
  zg := zg + length(n) * (r mod cf(length(n))+1-cf(i));
  for i := 1 to 9 do
    solve(i);
  out;
end.
Try input N=1 :) (-)
Posted by shitty.Mishka 6 Feb 2002 15:17