记录编号 13126 评测结果 WWWTTWWWAW
题目名称 单向双轨道 最终得分 10
用户昵称 GravatarAchilles 是否通过 未通过
代码语言 Pascal 运行时间 2.044 s
提交时间 2009-09-28 19:16:17 内存使用 0.14 MiB
显示代码纯文本
program track;
var
  n,i,m,ans,bl,cl,p,p2:integer;
  s:string;
  sz:array['a'..'z']of integer;
  a:array [1..10000]of record
    name,start,fuck:char;
  end;
  temp:char;
  b,c:array[1..30]of char;
begin
  assign(input,'track.in');
  assign(output,'track.out');
  reset(input);
  rewrite(output);
  readln(n);
  readln(s);
  i:=0;
  for temp:='a' to 'z' do
  begin
    i:=i+1;
    sz[temp]:=i;
  end;
  m:=1;
  i:=1;
  ans:=0;
  bl:=0;
  cl:=0;
  p:=0;
  while m<=n do
  begin
    p2:=0;
    if (sz[s[i]]=m)and(i<=n) then begin
      ans:=ans+1;
      a[ans].name:=s[i];
      a[ans].start:='A';
      a[ans].fuck:='D';
      i:=i+1;
      m:=m+1;
      p2:=1;
    end;
    if bl>0 then begin
      if sz[b[bl]]=m then begin
        ans:=ans+1;
        a[ans].name:=b[bl];
        a[ans].start:='B';
        a[ans].fuck:='D';
        m:=m+1;
        bl:=bl-1;
        p2:=1;
      end;
    end;
    if cl>0 then begin
      if sz[c[cl]]=m then begin
        ans:=ans+1;
        a[ans].name:=c[bl];
        a[ans].start:='C';
        a[ans].fuck:='D';
        m:=m+1;
        cl:=cl-1;
        p2:=0;
      end;
    end;
    if p2=0 then
    if (bl=0)and(i<=n) then begin
      ans:=ans+1;
      a[ans].name:=s[i];
      a[ans].start:='A';
      a[ans].fuck:='B';
      bl:=bl+1;
      b[bl]:=s[i];
      i:=i+1;
    end
    else begin
      if (sz[b[bl]]>sz[s[i]])and(i<=n) then begin
        ans:=ans+1;
        a[ans].name:=s[i];
        a[ans].start:='A';
        a[ans].fuck:='B';
        bl:=bl+1;
        b[bl]:=s[i];
        i:=i+1;
      end
      else begin
        if (cl=0)and(i<=n) then begin
          ans:=ans+1;
          a[ans].name:=s[i];
          a[ans].start:='A';
          a[ans].fuck:='C';
          cl:=cl+1;
          c[cl]:=s[i];
          i:=i+1;
        end
        else begin
          if (sz[c[cl]]>sz[s[i]])and(i<=n) then begin
            ans:=ans+1;
            a[ans].name:=s[i];
            a[ans].start:='A';
            a[ans].fuck:='C';
            cl:=cl+1;
            c[cl]:=s[i];
            i:=i+1;
          end
          else begin
            if bl>0 then begin
              if cl=0 then begin
                ans:=ans+1;
                a[ans].name:=b[bl];
                a[ans].start:='B';
                a[ans].fuck:='C';
                cl:=cl+1;
                c[cl]:=b[bl];
                bl:=bl-1;
              end
              else begin
                if sz[c[cl]]>sz[b[bl]] then begin
                  ans:=ans+1;
                  a[ans].name:=b[bl];
                  a[ans].start:='B';
                  a[ans].fuck:='C';
                  cl:=cl+1;
                  c[cl]:=b[bl];
                  bl:=bl-1;
                end
                else begin
                  p:=1;
                  writeln('NO');
                end;
              end;
            end;
          end;
        end;
      end;
    end;
  end;
  if p=0 then begin
    for i:=1 to ans do
    begin
      writeln(a[i].name,' ',a[i].start,' ',a[i].fuck);
    end;
  end;
  close(input);
  close(output);
end.