记录编号 270067 评测结果 AAAAAAAAAAAAAAA
题目名称 [USACO 1.2] 命名那个数字 最终得分 100
用户昵称 GravatarConanQZ 是否通过 通过
代码语言 Pascal 运行时间 0.026 s
提交时间 2016-06-14 13:36:01 内存使用 2.22 MiB
显示代码纯文本
program P1106;
type
 node=record
  w:array['A'..'Z']of longint;
  e:boolean;
 end;
var
i,root,ttot:longint;
s:string;
d:array[1..20010]of node;
v:array[2..9,1..3]of char;
p:boolean;

procedure tfirst;
var
i:longint;
begin
v[2,1]:='A'; v[2,2]:='B'; v[2,3]:='C';
v[3,1]:='D'; v[3,2]:='E'; v[3,3]:='F';
v[4,1]:='G'; v[4,2]:='H'; v[4,3]:='I';
v[5,1]:='J'; v[5,2]:='K'; v[5,3]:='L';
v[6,1]:='M'; v[6,2]:='N'; v[6,3]:='O';
v[7,1]:='P'; v[7,2]:='R'; v[7,3]:='S';
v[8,1]:='T'; v[8,2]:='U'; v[8,3]:='V';
v[9,1]:='W'; v[9,2]:='X'; v[9,3]:='Y';
end;

procedure put(id:longint;var t:longint);
begin
if t=0 then
  begin
   inc(ttot);
   t:=ttot;
   if id<=length(s) then put(id+1,d[t].w[s[id]]) else d[t].e:=true;
  end
else
  begin
   put(id+1,d[t].w[s[id]]);
  end;
end;

procedure dfs(id,t:longint; s1:string);
var
i,num:longint;
begin
if (id>length(s))and(d[t].e) then
  begin
   writeln(s1);
   p:=true;
   exit;
  end;
num:=ord(s[id])-ord('0');
for i:=1 to 3 do
  begin
   if d[t].w[v[num,i]]<>0 then
     begin
      dfs(id+1,d[t].w[v[num,i]],s1+v[num,i]);
     end;
  end;
end;

begin
//WRITELN('////////////////////////////////////////////////////////');
tfirst;
//assign(input,'11.in'); reset(input);
assign(input,'namenum.in'); reset(input);
assign(output,'namenum.out'); rewrite(output);
root:=1; ttot:=1;
for i:=1 to 4617 do
  begin
   readln(s);
   put(1,root);
  end;
readln(s);
dfs(1,root,'');
if not p then writeln('NONE');
end.