比赛 20090923练习赛 评测结果 WAWWW
题目名称 逻辑表达式 最终得分 20
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-09-23 21:44:26
显示代码纯文本
program express;
var
  p,i,temp:integer;
  s:string;
  jh,jh2,jh3:set of char;
begin
  jh:=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','+','*','~',
  '(',')'];
  jh2:=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','('];
  jh3:=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',')'];
  assign(input,'expressa.in');
  assign(output,'expressa.out');
  reset(input);
  rewrite(output);
  readln(s);
  p:=0;
  for i:=1 to length(s) do
  begin
    if not(s[i] in jh) then begin
      p:=1;
      writeln('no');
      break;
    end;
  end;
  if p=0 then begin
    temp:=0;
    for i:=1 to length(s) do
    begin
      if s[i]='(' then temp:=temp+1;
      if s[i]=')' then temp:=temp-1;
    end;
    if temp<>0 then begin
      writeln('no');
      p:=1;
    end
    else begin
      for i:=1 to length(s) do
      begin
        if s[i]='`' then begin
          if i=length(s) then begin
            writeln('no');
            p:=1;
            break;
          end
          else begin
            if not(s[i+1]in jh2) then begin
              writeln('no');
              p:=1;
              break;
            end;
          end;
        end;
        if (s[i]='+')or(s[i]='*') then begin
          if i=length(s) then begin
            writeln('no');
            p:=1;
            break;
          end
          else begin
            if (not(s[i-1]in jh3))or(not(s[i+1]in jh2)) then begin
              writeln('no');
              p:=1;
              break;
            end;
          end;
        end;
      end;
    end;
  end;
  if p=0 then writeln('yes');
  close(input);
  close(output);
end.