Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:想了半天终于看懂啦,有思路啦!In Reply To:想了半天终于看懂啦,有思路啦! Posted by:nan5515522 at 2014-04-28 22:51:28 贡献一次WA之后AC了,说话算话上代码 #include<iostream> #include<Cstdio> #include<stack> using namespace std; int hash[1000]; char input[5000]; int Cal1(int a, int b, char op) { if(op == 'K') return a & b; else if(op == 'A') return a | b; else if(op == 'E') return !(a ^ b); else { if(a == 1 && b == 1) return 1; else if(a == 1 && b == 0) return 0; else if(a == 0 && b == 1) return 1; else if(a == 0 && b == 0) return 1; } } int Judge(char* string) { stack<int>num; stack<char>sign; int i = 0, temp1, temp2, result; char temp, op; while(string[i] != '\0') i++; i--; while (i >= 0) { temp = string[i]; if(temp >= 'p' && temp <= 't') { num.push(hash[temp - 'p']); } else sign.push(temp); if(!sign.empty()) { op = sign.top(); sign.pop(); if(op == 'K' || op == 'A' || op == 'C' || op == 'E') { temp1 = num.top(); num.pop(); temp2 = num.top(); num.pop(); result = Cal1(temp1, temp2, op); num.push(result); } else { temp1 = num.top(); num.pop(); result = !temp1; num.push(result); } } i--; } while(!sign.empty()) { op = sign.top(); sign.pop(); if(op == 'K' || op == 'A' || op == 'C' || op == 'E') { temp2 = num.top(); num.pop(); temp1 = num.top(); num.pop(); result = Cal1(temp1, temp2, op); num.push(result); } else { temp1 = num.top(); num.pop(); result = !temp1; num.push(result); } } result = num.top(); //cout << result << endl; return result; } int Change(char* n) { int flag = 1; for(int i = 0; i < 32; ++i) { hash[0] = i & 1; hash[1] = (i >> 1) & 1; hash[2] = (i >> 2) & 1; hash[3] = (i >> 3) & 1; hash[4] = (i >> 4) & 1; flag = Judge(n); if(flag == 0) break; } return flag; } int main() { int res = -1; while(1) { cin >> input; if(input[0] == '0') break; res = Change(input); if(res == 1) cout << "tautology" << endl; else cout << "not" << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator