Poj 3295 Tautology

Source: Internet
Author: User

Mom, it turns out to be a discrete MATHEMATICAL question, a question, and an equivalent of disjunction, union, non, implication .... Thanks to the end of the final exam, it would be sad ,,,,

The general meaning of this question is to determine whether the given formula is a permanent, true, or a total of five elements. The given string is a suffix expression of the formula .. First, convert to judgment .. 2 ^ 5 in 32 cases in total, if the enumeration is false, mark the output not. Otherwise, tautology ,,,,

I will not repeat the following code...

#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX 110int main(){    char s[MAX], s1[MAX], str[MAX];    int t, k, i, j, flat;    int num[32][5] =    {        1,1,1,1,1,        1,1,1,1,0,        1,1,1,0,1,        1,1,1,0,0,        1,1,0,1,1,        1,1,0,1,0,        1,1,0,0,1,        1,1,0,0,0,        1,0,1,1,1,        1,0,1,1,0,        1,0,1,0,1,        1,0,1,0,0,        1,0,0,1,1,        1,0,0,1,0,        1,0,0,0,1,        1,0,0,0,0,        0,1,1,1,1,        0,1,1,1,0,        0,1,1,0,1,        0,1,1,0,0,        0,1,0,1,1,        0,1,0,1,0,        0,1,0,0,1,        0,1,0,0,0,        0,0,1,1,1,        0,0,1,1,0,        0,0,1,0,1,        0,0,1,0,0,        0,0,0,1,1,        0,0,0,1,0,        0,0,0,0,1,        0,0,0,0,0,    };    while(~scanf("%s",s))    {        flat = 0;        k = strlen(s);        if(k == 1 && s[0] == '0')            break;        for(i = 0; i < 32; i++)        {            t = 0;            for(j = 0; j < k; j++)            {                if(s[j] == 'p')                    s1[j] = num[i][0] + '0';                else if(s[j] == 'q')                    s1[j] = num[i][1] + '0';                else if(s[j] == 'r')                    s1[j] = num[i][2] + '0';                else if(s[j] == 's')                    s1[j] = num[i][3] + '0';                else if(s[j] == 't')                    s1[j] = num[i][4] + '0';                else                    s1[j] = s[j];            }            for(j = k-1; j >= 0; j--)            {                if(s1[j] == '0' || s1[j] == '1')                {                    str[t++] = s1[j];                }                else if(s1[j] == 'K')                {                    str[t-2] = ((str[t-2]-'0')&&(str[t-1]-'0'))+'0';                    t--;                }                else if(s1[j] == 'A')                {                    str[t-2] = ((str[t-2]-'0')||(str[t-1]-'0'))+'0';                    t--;                }                else if(s1[j] == 'C')                {                    str[t-2] = ((!(str[t-2]-'0'))||(str[t-1]-'0'))+'0';                    t--;                }                else if(s1[j] == 'E')                {                    str[t-2] = ((str[t-2]-'0')==(str[t-1]-'0'))+'0';                    t--;                }                else if(s1[j] == 'N')                {                    str[t-1] = (!(str[t-1]-'0'))+'0';                }            }            if(str[0] == '0')                flat = 1;        }        if(flat == 0)            printf("tautology\n");        else            printf("not\n");    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.