⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lgame.pas

📁 Magio牛的usaco源代码
💻 PAS
字号:
{
ID:maigoak1
PROG:lgame
}

program lgame;
const
  maxdict=40000;
  value:array['a'..'z']of byte=(2,5,4,4,1,6,5,5,1,7,6,3,5,2,3,5,7,2,1,2,4,6,6,7,5,7);
type
  str7=string[7];
var
  fin,fout:text;
  dict:array[1..maxdict]of str7;
  score:array[1..maxdict]of byte;
  dictsize,i,j:word;
  usable,s:str7;
  top,max,t:byte;
function ok(s:string):boolean;
  var
    u:str7;
    i,p:byte;
  begin
    ok:=false;
    u:=usable;
    for i:=1 to length(s) do begin
      p:=pos(s[i],u);
      if p=0 then exit;
      delete(u,p,1);
    end;
    ok:=true;
  end;
function calscore(s:str7):byte;
  var
    i:byte;
  begin
    calscore:=0;
    for i:=1 to length(s) do
      inc(calscore,value[s[i]]);
  end;
begin
  assign(fin,'lgame.in');
  reset(fin);
  readln(fin,usable);
  close(fin);

  dictsize:=0;max:=0;
  assign(fin,'lgame.dict');
  reset(fin);
  readln(fin,s);
  repeat
    if ok(s) then begin
      inc(dictsize);
      dict[dictsize]:=s;
      score[dictsize]:=calscore(s);
      if score[dictsize]>max then max:=score[dictsize];
    end;
    readln(fin,s);
  until s='.';
  close(fin);

  top:=calscore(usable);
  for i:=1 to dictsize-1 do begin
    if max=top then break;
    for j:=i to dictsize do begin
      if ok(dict[i]+dict[j]) then begin
        t:=score[i]+score[j];
        if t>max then max:=t;
      end;
      if max=top then break;
    end;
  end;

  assign(fout,'lgame.out');
  rewrite(fout);
  writeln(fout,max);
  for i:=1 to dictsize do begin
    if score[i]=max then writeln(fout,dict[i]);
    for j:=i+1 to dictsize do
      if ok(dict[i]+dict[j]) then
        if score[i]+score[j]=max then writeln(fout,dict[i],' ',dict[j]);
  end;
  close(fout);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -