写一大堆然后一次ac的感觉好爽好爽!!!
第一次用stl
是的,上大学两年来第一次用stl!!!
啊!!!我该鄙视自己还是佩服自己!!!
其实差不多就是四则运算那种,pqrst代表五个值,都是0或1,然后把它们代入表达式,akcge代表运算符,或、与、非balabala
如果不管pqrst的组合怎样最终结果都为1的话就tautlogy,否则就是not
四则运算和表达式运算一般就和栈有关吧,然后stl还是很强大的嘎嘎嘎嘎嘎,在这道题里用起来很方便啊
但是为啥老师给我的任务说这是分治递推题呢……估计我还是不能完全理解分治递推啥意思
感觉自己写的代码比网上的简洁一点,估计是今天男盆友要回来了心情格外好一点哈哈
#include <iostream>
#include <stack>
#include <string.h>
using namespace std;
stack<int> the_stack;
int operator_string(int p,int q,int r,int s,int t,char wff[103])
{
int len=strlen(wff);
int i;
for (i=len-1; i>=0; i--) {
if (wff[i]=='p')
the_stack.push(p);
if (wff[i]=='q')
the_stack.push(q);
if (wff[i]=='r')
the_stack.push(r);
if (wff[i]=='s')
the_stack.push(s);
if (wff[i]=='t')
the_stack.push(t);
if (wff[i]=='A') {
int x=the_stack.top();
the_stack.pop();
int y=the_stack.top();
the_stack.pop();
the_stack.push(x||y);
}
if (wff[i]=='K') {
int x=the_stack.top();
the_stack.pop();
int y=the_stack.top();
the_stack.pop();
the_stack.push(x&&y);
}
if (wff[i]=='C') {
int x=the_stack.top();
the_stack.pop();
int y=the_stack.top();
the_stack.pop();
the_stack.push((!x)||y);
}
if (wff[i]=='E') {
int x=the_stack.top();
the_stack.pop();
int y=the_stack.top();
the_stack.pop();
the_stack.push(x==y);
}
if (wff[i]=='N') {
int x=the_stack.top();
the_stack.pop();
the_stack.push(!x);
}
}
i=the_stack.top();
the_stack.pop();
return i;
}
int main(int argc, const char * argv[]) {
char wff[103];
while (cin>>wff) {
if (wff[0]=='0')
return 0;
if(operator_string(0, 0, 0, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 0, 0, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 0, 0, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 0, 0, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 0, 1, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 0, 1, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 0, 1, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 0, 1, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 0, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 0, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 0, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 0, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 1, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 1, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 1, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(0, 1, 1, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 0, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 0, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 0, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 0, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 1, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 1, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 1, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 0, 1, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 0, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 0, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 0, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 0, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 1, 0, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 1, 0, 1,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 1, 1, 0,wff)==0)
{cout<<"not"<<endl;continue;}
if(operator_string(1, 1, 1, 1, 1,wff)==0)
{cout<<"not"<<endl;continue;}
cout<<"tautology"<<endl;
}
return 0;
}