本文共 1196 字,大约阅读时间需要 3 分钟。
代码:
#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define LL long long#define sint short intconst int INF=0x3f3f3f3f;//priority_queue ,greater >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 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"<
转载于:https://www.cnblogs.com/liulangye/archive/2012/12/05/2803596.html