Poj 3295

题目大意:略

解:暴力枚举rqst之流的状态就行了,状态数不多,对运算顺序困惑了下,看了看题解是用栈自后往前弄。

View Code
 1 //Tautology
 2 const
 3         ttttt='tautology';
 4         fffff='not';
 5         inf='1.txt';
 6         maxl=111;
 7 var
 8         ask: string;
 9         ans: boolean;
10         stack: array[0..maxl]of longint;
11         tot : longint;
12 
13 procedure main;
14 var
15         l, tmp, p, q, r, s, t: longint;
16         c: char;
17 begin
18   ans := true;
19   for p := 0 to 1 do
20     for q := 0 to 1 do
21       for r := 0 to 1 do
22         for s := 0 to 1 do
23           for t := 0 to 1 do begin
24             l := length(ask);
25             tot := 0;
26             while l>0 do begin
27               c := ask[l];
28               case c of
29                 'q', 'p', 'r', 's', 't': begin
30                   inc(tot);
31                   case c of
32                     'q':stack[tot] := q;
33                     'p':stack[tot] := p;
34                     'r':stack[tot] := r;
35                     's':stack[tot] := s;
36                     't':stack[tot] := t;
37                   end;
38                 end;
39                 'N':stack[tot] := stack[tot] xor 1 ;
40                 'K':begin
41                   dec(tot);
42                   stack[tot] := stack[tot] and stack[tot+1];
43                 end;
44                 'A':begin
45                   dec(tot);
46                   stack[tot] := stack[tot] or stack[tot+1];
47                 end;
48                 'C':begin
49                   dec(tot);
50                   stack[tot] := ((stack[tot]xor stack[tot+1])xor 1)or(stack[tot])
51                 end;
52                 'E':begin
53                   dec(tot);
54                   stack[tot] := (stack[tot]xor stack[tot+1])xor 1;
55                 end;
56               end;
57               dec(l);
58             end;
59             if stack[1]=0 then begin
60               ans := false; exit;
61             end;
62           end;
63 end;
64 
65 procedure print;
66 begin
67   if ans then writeln(ttttt)
68     else writeln(fffff);
69 end;
70 
71 begin
72   assign(input,inf); reset(input);
73   read(ask); readln;
74   while ask<>'0' do begin
75     main;
76     print;
77     read(ask); readln;
78   end;
79 end.
原文地址:https://www.cnblogs.com/wmzisfoolish/p/2490581.html