POJ Tautology

た 入场券 2022-07-10 04:16 227阅读 0赞

Tautology














Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12751   Accepted: 4861

Description

WFF ‘N PROOF is a logic game played with dice. Each die has six faces representing some subset of the possible symbols K, A, N, C, E, p, q, r, s, t. A Well-formed formula (WFF) is any string of these symbols obeying the following rules:

  • p, q, r, s, and t are WFFs
  • if w is a WFF, Nw is a WFF
  • if w and x are WFFs, Kwx, Awx, Cwx, and Ewx are WFFs.

The meaning of a WFF is defined as follows:

  • p, q, r, s, and t are logical variables that may take on the value 0 (false) or 1 (true).
  • K, A, N, C, E mean and, or, not, implies, and equals as defined in the truth table below.






Definitions of K, A, N, C, and E











































     w  x   Kwx   Awx    Nw   Cwx   Ewx
  1  1   1   1    0   1   1
  1  0   0   1    0   0   0
  0  1   0   1    1   1   0
  0  0   0   0    1   1   1

A tautology is a WFF that has value 1 (true) regardless of the values of its variables. For example, ApNp is a tautology because it is true regardless of the value of p. On the other hand, ApNq is not, because it has the value 0 for p=0, q=1.

You must determine whether or not a WFF is a tautology.

Input

Input consists of several test cases. Each test case is a single line containing a WFF with no more than 100 symbols. A line containing 0 follows the last case.

Output

For each test case, output a line containing tautology or not as appropriate.

Sample Input

  1. ApNp
  2. ApNq
  3. 0

Sample Output

  1. tautology
  2. not
  3. #include <iostream>
  4. using namespace std;
  5. const int maxn = 105;
  6. char str[maxn];
  7. int flag[10];
  8. int start;
  9. int judge()
  10. {
  11. int p,q;
  12. switch(str[++start])
  13. {
  14. case 'K': p = judge(); q = judge();return (p&&q);
  15. case 'A': p = judge(); q = judge();return (p||q);
  16. case 'N': return (!judge());
  17. case 'C': p = judge(); q = judge();return (!p||q);
  18. case 'E': return (judge() == judge());
  19. default : return (flag[str[start] - 'p']);
  20. }
  21. }
  22. int main()
  23. {
  24. while(cin>>str)
  25. {
  26. if(str[0] == '0')
  27. break;
  28. int ans = 1;
  29. for(int i=0;i<2;i++)
  30. {
  31. flag[0] = i;
  32. for(int j=0;j<2;j++)
  33. {
  34. flag[1] = j;
  35. for(int k=0;k<2;k++)
  36. {
  37. flag[2] = k;
  38. for(int s=0;s<2;s++)
  39. {
  40. flag[3] = s;
  41. }
  42. for(int t=0;t<2;t++)
  43. {
  44. flag[4] = t;
  45. start = -1;
  46. ans = (ans&&judge());
  47. if(!ans)
  48. break;
  49. }
  50. }
  51. }
  52. }
  53. if (!ans)cout<<"not"<<"\n";
  54. else cout<<"tautology"<<"\n";
  55. }
  56. return 0;
  57. }

发表评论

表情:
评论列表 (有 0 条评论,227人围观)

还没有评论,来说两句吧...

相关阅读

    相关 poj 1009

    参考自大神思路:[POJ 1009][] 首先,暴力必挂,这是题目的善意提醒。 于是,一直在想不暴力的各种判断计算方法,关于各种跳跃移动,后来都无奈想用STL。原谅我的