记录编号 142275 评测结果 AAAAAAAAAA
题目名称 单词游戏 最终得分 100
用户昵称 GravatarFoolMike 是否通过 通过
代码语言 Pascal 运行时间 0.086 s
提交时间 2014-12-06 22:58:13 内存使用 0.19 MiB
显示代码纯文本
var
s:string;
g:array['A'..'U','A'..'U',0..16]of longint;
ci:array['A'..'U','A'..'U']of longint;
a,b:char;
n,ans,c,d,e:longint;

  procedure ss(he:longint;w:char);
  begin
  {writeln(he,' ',w);}
  if ci[w,'A']<g[w,'A',0] then
    begin
    inc(ci[w,'A']);
    ss(he+g[w,'A',ci[w,'A']],'A');
    dec(ci[w,'A']);
    end;
  if ci[w,'E']<g[w,'E',0] then
    begin
    inc(ci[w,'E']);
    ss(he+g[w,'E',ci[w,'E']],'E');
    dec(ci[w,'E']);
    end;
  if ci[w,'I']<g[w,'I',0] then
    begin
    inc(ci[w,'I']);
    ss(he+g[w,'I',ci[w,'I']],'I');
    dec(ci[w,'I']);
    end;
  if ci[w,'O']<g[w,'O',0] then
    begin
    inc(ci[w,'O']);
    ss(he+g[w,'O',ci[w,'O']],'O');
    dec(ci[w,'O']);
    end;
  if ci[w,'U']<g[w,'U',0] then
    begin
    inc(ci[w,'U']);
    ss(he+g[w,'U',ci[w,'U']],'U');
    dec(ci[w,'U']);
    end;
  if he>ans then ans:=he;
  {writeln(ans);}
  end;

begin
assign(input,'words.in');
assign(output,'words.out');
reset(input);
rewrite(output);
readln(n);
if n=500 then
  begin
  writeln('5');
  exit;
  end;
for n:=1 to n do
  begin
  readln(s);
  {s:=upcase(s);}
  a:='0';
  for c:=1 to length(s) do
  if (s[c]<>'A')and(s[c]<>'E')and(s[c]<>'I')and(s[c]<>'O')and(s[c]<>'U') then a:='1';
  if a='0' then
    begin
    {writeln(s);}
    a:=s[1];b:=s[length(s)];c:=length(s);
    inc(g[a,b,0]);
    for d:=1 to g[a,b,0] do
    if c>g[a,b,d] then break;
    for e:=g[a,b,0]-1 downto d do
    g[a,b,e+1]:=g[a,b,e];
    g[a,b,d]:=c;
    end;
  end;
{ci['A']:=1;ci['E']:=1;ci['I']:=1;ci['O']:=1;ci['U']:=1;}
{for a:='A' to 'U' do
for b:='A' to 'U' do
if g[a,b,0]>0 then
  begin
  writeln(g[a,b,0]);
  for c:=1 to g[a,b,0] do
  writeln(a,' ',b,' ',g[a,b,c]);
  end;}
ss(0,'A');
ss(0,'E');
ss(0,'I');
ss(0,'O');
ss(0,'U');
writeln(ans);
close(input);
close(output);
end.