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 |
没道理啊 怎么会TLE 大牛大虾帮忙seesee#include<iostream> #include<stack> using namespace std; char Precede(char x, char y) { //cout << x << y << endl; if(x == '!') { if(y == '(' || y == '!') //后者是为了 !!!F 多个叹号的出现 return '<'; return '>'; } if(x == '&') { if(y == '!' || y == '(') return '<'; return '>'; } if(x == '|') { if(y == '|' || y == ')' || y == '#') return '>'; return '<'; } if(x == '(') { if(y == ')') return '='; return '<'; } if(x == ')') return '>'; if(x == '#') { if(y == '#') return '@'; return '<'; } } char Operate(char a, char m, char b) { if(a == 'F' && b == 'F') return 'F'; if(a == 'V' && b == 'V') return 'V'; if(a == 'V' && b == 'F' || a == 'F' && b == 'V') { if(m == '&') return 'F'; else return 'V'; } } int main() { stack<char> s1; //F V stack<char> s2; //运算符 char a, b, m, c; int gg = 1; while(scanf("%c", &c) != EOF) { s1.empty(), s2.empty(); s2.push('#'); //c = getchar(); while(c == ' ') c = getchar(); while(c != '#' || s2.top() != '#') { //if(s2.size() == 0) // break; while(c == ' ') c = getchar(); if(c == '\n') c = '#'; //cout <<c<< " "<< s2.top() <<" "<<s2.size()<< endl; if(c == 'F' || c == 'V') s1.push(c), c = getchar(); else { //cout << " "<<Precede(s2.top(), c) << endl; switch(Precede(s2.top(), c)) { case '<' : s2.push(c); c = getchar();break; case '=' : s2.pop(); c = getchar(); break; case '>' : m = s2.top(), s2.pop(); a = s1.top(), s1.pop(); if(m != '!') { b = s1.top(), s1.pop(); s1.push(Operate(a, m, b)); break;} else {if(a == 'F') s1.push('V'); else s1.push('F'); break;} case '@' : goto X; } }//cout << "s1.top() "<<s1.top() << endl; } // cout << "s1.top() "<<s1.top() << endl; X: printf("Expression %d: %c\n", gg ++, s1.top()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator