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
ApNp
ApNq
0
Sample Output
tautology
not
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
int p,q,r,s,t;
bool sta[200];
char str[200];
int top;
void fun(char c)
{
switch(c)
{
case 'K':
{
int x=sta[--top];
int y=sta[--top];
sta[top++]=(x&&y);
break;
}
case 'A':
{
int x=sta[--top];
int y=sta[--top];
sta[top++]=(x||y);
break;
}
case 'N':
{
int x=sta[--top];
sta[top++]=!x;
break;
}
case 'C':
{
int x=sta[--top];
int y=sta[--top];
sta[top++]=((!x)||y);
break;
}
case 'E':
{
int x=sta[--top];
int y=sta[--top];
sta[top++]=(x==y);
break;
}
}
}
void fun2(int i)
{
switch(str[i])
{
case 'p':
{
if(p)
sta[top++]=true;
else
sta[top++]=false;
break;
}
case 'q':
{
if(q)
sta[top++]=true;
else
sta[top++]=false;
break;
}
case 'r':
{
if(r)
sta[top++]=true;
else
sta[top++]=false;
break;
}
case 's':
{
if(s)
sta[top++]=true;
else
sta[top++]=false;
break;
}
case 't':
{
if(t)
sta[top++]=true;
else
sta[top++]=false;
break;
}
}
}
int main()
{
while(cin>>str)
{
if(str[0]=='0') break;
top=0;
int len=strlen(str),flag=0;
for(p=0;p<=1;p++)
{
for(q=0;q<=1;q++)
{
for(r=0;r<=1;r++)
{
for(s=0;s<=1;s++)
{
for(t=0;t<=1;t++)
{
for(int i=len-1;i>=0;i--)
{
if(str[i]=='p'||str[i]=='q'||str[i]=='r'||str[i]=='s'||str[i]=='t')
{
fun2(i);
}
else
fun(str[i]);
}
if(!sta[--top])
{
flag=1;
break;
}
}
if(flag) break;
}
if(flag) break;
}
if(flag) break;
}
if(flag) break;
}
if(!flag)
printf("tautology\n");
else
printf("not\n");
}
}