Source Code Status Test Cases
    Policy: public     Reviewed: 18    
00.00 sec    3128 KB    96 lines     2382 bytes    2017-05-22 10:28
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

typedef string::const_iterator State;
int countMinus(State&);
int negative(int,int);
int number(State&);
int factor(State&);
int expression(State&);

int p, q, r;

int inverted(int ret){
    if(ret == 0) return 2;
    else if(ret == 2) return 0;
    else return 1;
}

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;
    if(*begin == 'P') ret = p;
    else if(*begin == 'Q') ret = q;
    else if(*begin == 'R') ret = r;
    else if(isdigit(*begin)) ret = *begin - '0';
    else return 0;

    begin++;
    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
int factor(State &begin) {
    int ret;
    if (*begin == '(') {
        begin++; // '('????£???°??????
        ret = expression(begin);
        begin++; // ')'????£???°??????
        return ret;
    }else {
        return number(begin);
    }
}

int term(State &begin){
    if (*begin == '-') {
        begin++;
        return inverted(term(begin));
    } else {
        return factor(begin);
    }
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret = max(ret, term(begin));
        } else if (*begin == '*') {
            begin++;
            ret = min(ret, term(begin));
        } else {
            break;
        }
    }

    return ret;
}

int main(){
    string s;
    while(cin >> s, s[0] != '.'){
        int cnt = 0;
        for(p = 0; p < 3; p++){
            for(q = 0; q < 3; q++){
                for(r = 0; r < 3; r++){
                    State tmp = s.begin();
                    if(expression(tmp) == 2){
                        //cout << p << ' ' << q << ' ' << r << endl;
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 C++11 CPU: 00.00 sec Memory: 3128 KB Length: 2382 B 2017-05-22 10:28 2017-05-22 10:28
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.00 sec 3128 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags