http://poj.org/problem?id=3295
代码:
#include<iostream> #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<vector> #include<set> #include<map> #include<string> #include<queue> #include<stack> #include <iomanip> using namespace std; #define LL long long #define sint short int const int INF=0x3f3f3f3f; //priority_queue<int,vector<int>,greater<int> >qt; bool a[7]; bool ans; string s; bool K(char k,bool t1) { return (!t1); } bool K(char k,bool t1,bool t2) { if(k=='K') return (t1&&t2); if(k=='A') return (t1||t2); if(k=='C') return ((!t1)||t2); if(k=='E') return (t1==t2); return true; } void test() { stack<bool>st; for(int i=s.length()-1;i>=0;--i) { if(s[i]<='t'&&s[i]>='p') st.push(a[s[i]-'p']); else { bool tmp1,tmp2; if(s[i]=='N') { tmp1=st.top();st.pop(); st.push(K(s[i],tmp1)); }else { tmp1=st.top();st.pop(); tmp2=st.top();st.pop(); st.push(K(s[i],tmp1,tmp2)); } } } if(st.top()==false) ans=st.top(); } void dfs(int x) { if(x==5) {test();return ;} a[x]=true; dfs(x+1); a[x]=false; dfs(x+1); if(ans==false) return ; } int main() { //freopen("data.in","r",stdin); while(cin>>s) { if(s=="0") break; ans=true; dfs(0); if(ans) cout<<"tautology"<<endl; else cout<<"not"<<endl; } return 0; }