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

Re:小心编译器的选择

Posted by 201358505106 at 2014-09-22 20:30:53 on Problem 3295
In Reply To:小心编译器的选择 Posted by:ENIAC at 2008-07-17 12:50:22
> 如果你是bool型判断与、或等等用&&,||的话,选C++会WA,不知道为什么!!选G++就AC了。
> 用位运算的&、|两个都可以过。
我用的&&、||的咋都能过呢???
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<stack>
using namespace std;
stack<bool>st;
int p,q,r,s,t;
bool isvariables(char c){
    if(c=='p') return 1;
    if(c=='q') return 1;
    if(c=='r') return 1;
    if(c=='s') return 1;
    if(c=='t') return 1;
    return 0;
}
void push(char c){
    if(c=='p') st.push(p);
    else if(c=='q') st.push(q);
    else if(c=='r') st.push(r);
    else if(c=='s') st.push(s);
    else if(c=='t') st.push(t);
    return;
}
void f(char c){
    bool a,b;
    if(c=='K'){
        a=st.top();
        st.pop();
        b=st.top();
        st.pop();
        st.push(a&&b);
    }
    else if(c=='A'){
        a=st.top();
        st.pop();
        b=st.top();
        st.pop();
        st.push(a||b);
    }
    else if(c=='N'){
        a=st.top();
        st.pop();
        st.push(!a);
    }
    else if(c=='C'){
        a=st.top();
        st.pop();
        b=st.top();
        st.pop();
        st.push((!a)||b);
    }
    else if(c=='E'){
        a=st.top();
        st.pop();
        b=st.top();
        st.pop();
        st.push(a==b);
    }
    return;
}
int main(){
    char wff[110];
    while(scanf("%s",wff)&&wff[0]!='0'){
        int len=strlen(wff);
        bool flag=1;
        int i;
        for(p=0;p<=1;p++){
            for(q=0;q<=1;q++){
                 for(r=0;r<=1;r++){
                    for(s=0;s<=1;s++){
                        for(t=0;t<=1;t++){
                            for(i=len-1;i>=0;i--){
                                if(isvariables(wff[i]))
                                    push(wff[i]);
                                else
                                    f(wff[i]);
                            }
                            if(st.top()==0)
                                flag=0;
                            st.pop();
                        }
                    }
                 }
            }
        }
        if(flag)
            printf("tautology\n");
        else
            printf("not\n");
    }
}

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