http://acm.pku.edu.cn/JudgeOnline/problem?id=1126
http://acm.pku.edu.cn/JudgeOnline/problem?id=3295
两道题目很相似,都是对一个字符串进行分析,并得出结果,核心思想使用递归下降的方法
code 1126
- #include<iostream>
- #include<string>
- usingnamespacestd;
- intj(0);
- stringtemp;
- intcheck();
- intmain()
- {
- freopen("in.txt","r",stdin);
- intf;
- while(cin>>temp)
- {
- f=check();
- if(j<temp.size())//如果调用完后,j<temp.size()那么就为错
- f=0;
- j=0;
- if(f)
- cout<<"YES"<<endl;
- else
- cout<<"NO"<<endl;
- }
- return0;
- }
- intcheck()
- {
- intch=temp[j++];
- switch(ch)
- {
- case'p':case'q':case'r':case's':case't':case'u':case'v':case'w':case'x':case'y':case'z':return1;break;
- case'I':case'E':case'D':case'C':returncheck()&check();break;
- case'N':returncheck();break;
- default:return0;
- }
- }
code 3295
- #include<iostream>
- usingnamespacestd;
- intcheck();
- intj(0);
- chartemp[201];
- shortv[200]={0};
- intmain()
- {
- freopen("in.txt","r",stdin);
- intp,q,r,s,t,f(1);
- while(cin>>temp&&temp[0]!='0')
- {
- f=1;
- j=0;
- //对32 种情况的枚举
- for(p=0;p<=1&&f;p++)
- for(q=0;q<=1&&f;q++)
- for(r=0;r<=1&&f;r++)
- for(s=0;s<=1&&f;s++)
- for(t=0;t<=1&&f;t++)
- {
- v['p'-'0']=p;
- v['q'-'0']=q;
- v['r'-'0']=r;
- v['s'-'0']=s;
- v['t'-'0']=t;
- j=0;
- f=check();
- if(f==0)
- {
- cout<<"not"<<endl;
- break;
- }
- }
- if(f)
- cout<<"tautology"<<endl;
- }
- return0;
- }
- intcheck(){
- intch=temp[j++];
- switch(ch){
- case'p':case'q':case'r':case's':case't':returnv[ch-'0'];break;
- case'K':returncheck()&check();break;
- case'A':returncheck()|check();break;
- case'N':return!check();break;
- case'C':return!check()|check();break;
- case'E':return!check()^check();break;
- }
- }

被折叠的 条评论
为什么被折叠?



