Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Why WA? Help Me!!

Posted by jimmyzzxhlh at 2003-10-11 15:35:10 on Problem 1016
const
  MaxN = 20;

var
  a : array[1..MaxN] of string;
  b : array[0..9] of integer;
  s,s1,ss : string;
  t,i,k,l : integer;

procedure trim(var s : string);
begin
  while s[1] = ' ' do delete(s,1,1);
  while s[length(s)] = ' ' do delete(s,length(s),1);
end;

begin
  readln(s);
  trim(s);
  while s <> '-1' do begin
    fillchar(a,sizeof(a),0);
    t := 1; a[1] := s; k := 0; l := 0;
    repeat
      fillchar(b,sizeof(b),0);
      for i := 1 to length(a[t]) do inc(b[ord(a[t][i]) - 48]);
      s1 := '';
      for i := 0 to 9 do
      if b[i] <> 0 then begin
        str(b[i],ss);
        s1 := s1 + ss + chr(i + 48);
      end;
      inc(t); a[t] := s1;
      if a[t - 1] = a[t] then begin
        k := 1; break;
      end;
      for i := 1 to t - 1 do
      if a[i] = a[t] then begin
        k := 2; l := i; break;
      end;
      if k <> 0 then break;
    until t > 15;
    if k = 1 then
    if t = 2
    then writeln(a[1],' is self-inventorying')
    else writeln(a[1],' is self-inventorying after ',t - 2,' steps');
    if k = 2 then writeln(a[1],' enters an inventory loop of length ',t - l);
    if t > 15
    then writeln(a[1],' can not be classified after 15 iterations');
    readln(s);
    trim(s);
  end;
end.





Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator