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

📄 ac1130.pas

📁 某牛人写的acm.tongji.edu.cn上大部分ac的代码,仅供学习研究,请不要用来作弊
💻 PAS
字号:
program tju1130;
const
  maxn=50;
type
  statement=record
    subj,obj,what:shortint;
    {obj:0:day/night;1..5:person;
     what:0:day,1:night;
          1:evil;2:human;3:divine;
          -1:not evil;-2:not human;-3:not divine}
  end;
var
  info:array[1..maxn]of statement;
  appear:array[1..5]of boolean;
  id,ansid:array[1..5]of byte;
  n,i,count:byte;
  s:string;
  day,ansday:boolean;
function bool(x:byte):boolean;
  begin
    with info[x] do
      if obj=0 then
        bool:=day=(what=0)
      else if what>0 then
        bool:=id[obj]=what
      else
        bool:=id[obj]<>-what;
  end;
procedure check;
  var
    i:byte;
  begin
    for i:=1 to n do
      with info[i] do
        if ((id[subj]=3) or (id[subj]=2) and not day)<>bool(i) then exit;
    inc(count);
    if count=2 then exit;
    ansid:=id;ansday:=day;
  end;
procedure search(l:byte);
  var
    i:byte;
  begin
    if count=2 then
      exit
    else if l>5 then
      check
    else if not appear[l] then
      search(l+1)
    else
      for i:=1 to 3 do begin
        id[l]:=i;
        search(l+1);
      end;
  end;
begin
  repeat
    fillchar(appear,sizeof(appear),0);
    readln(n);
    for i:=1 to n do begin
      readln(s);
      with info[i] do begin
        subj:=ord(s[1])-64;
        if s[4]='t' then begin
          obj:=0;
          if s[length(s)-1]='y' then what:=0 else what:=1;
        end
        else begin
          if s[3]='I' then obj:=subj else obj:=ord(s[3])-64;
          case s[length(s)-1] of
            'l':what:=1;'n':what:=2;'e':what:=3;
          end;
          if s[8]='n' then what:=-what;
        end;
        appear[subj]:=true;if obj>0 then appear[obj]:=true;
      end;
    end;

    count:=0;
    for day:=false to true do
      search(1);
    if count=0 then
      writeln('Impossible')
    else if count=2 then
      writeln('Can not determine')
    else begin
      for i:=1 to 5 do
        if appear[i] then
          case ansid[i] of
            1:writeln('evil');
            2:writeln('human');
            3:writeln('divine');
          end;
      if ansday then writeln('day') else writeln('night');
    end;
  until seekeof;
end.

⌨️ 快捷键说明

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