Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

新人贴代码留念,简单的递归

Posted by Anz at 2017-02-01 11:19:36 on Problem 3295
#include<iostream>
#include<cstring>
#include<cassert>

using namespace std;

string s;int cur;char a[5];

void Change(char i)//穷举时改变数组用的函数
{
    for(int j=0;j!=5;j++)
        a[j]=((i>>j)&00000001);
}
bool Cal()//递归
{
    char c=s[cur];bool w,x;
    cur++;
    switch(c){
    case 'p':return a[0];
    case 'q':return a[1];
    case 'r':return a[2];
    case 's':return a[3];
    case 't':return a[4];
    case 'N':return !Cal();
    case 'K':w=Cal();x=Cal();return (w&&x);
    case 'A':w=Cal();x=Cal();return (w||x);
    case 'C':w=Cal();x=Cal();return (w<=x);
    case 'E':w=Cal();x=Cal();return (w==x);
    default :return 0;
    }
}
int main()
{
    int f;
    while(1)
    {
        cin>>s;
        if(s=="0")  break;
        f=1;
        for(char i=0;i!=32;i++)
        {
            cur=0;Change(i);
            if(!Cal()) {f=0;break;}
        }
        if(f==1) cout<<"tautology"<<endl;
        else cout<<"not"<<endl;

    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator