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 |
为什么一直OLE啊,请大家帮忙看看#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <string> #include <iomanip> #include <cstdio> #include <cctype> #include <cmath> #include <cstdlib> #include <queue> using namespace std; /* ½«ÊäÈëת»»Îªºó׺±í´ïʽ,È»ºóÇó½â */ string getPostfix(int x,int y); void goEnd(int &x,int &y); int getResult(string postfix); char OR(char a,char b); char AND(char a,char b); char NOT(char a); #define MAX 102 char input[21]; char cir[MAX][MAX]; int main() { int cirCount=0; int i,j,cirCnt; int x0,y0; while(cin) { if(cirCount==0) { cirCount=1; } else if(cirCount==1) { cout<<endl; } //init for(i=0;i<MAX;i++) { for(j=0;j<MAX;j++) { cir[i][j]=' '; } } //cin [][] cirCnt=1; if(cin.peek()==EOF) { return 0; } cin.getline(cir[cirCnt++],MAX-2); while(strcmp(cir[cirCnt-1],"*")) { cin.getline(cir[cirCnt++],MAX-2); } bool ok=false; for(i=cirCnt-2;i>0;i--) { for(j=MAX-1;j>0;j--) { if(cir[i][j]=='?') { x0=j; y0=i; cir[i][j]='+'; ok=true; break; } } if(ok) { break; } } string postfix= getPostfix(x0,y0); cin.getline(input,22); while(strcmp(input,"*")) { cout<<getResult(postfix)<<"\n"; cin.getline(input,22); } } return 0; } int getResult(string postfix) { stack<char> st; for(int i=postfix.length()-1;i>=0;i--) { if(postfix[i]=='&') { char tmp1,tmp2; tmp1=st.top(); st.pop(); tmp2=st.top(); st.pop(); st.push(AND(tmp1,tmp2)); } else if(postfix[i]=='|') { char tmp1,tmp2; tmp1=st.top(); st.pop(); tmp2=st.top(); st.pop(); st.push(OR(tmp1,tmp2)); } else if(postfix[i]=='-') { char tmp; tmp = st.top(); st.pop(); st.push(NOT(tmp)); } else { st.push(input[postfix[i]-'A']); } } return st.top()=='1'?1:0; } char OR(char a,char b) { return a=='0'&&b=='0'?'0':'1'; } char AND(char a,char b) { return a=='1'&&b=='1'?'1':'0'; } char NOT(char a) { return a=='1'?'0':'1'; } string getPostfix(int x,int y) { string partPostfix; partPostfix.erase(); goEnd(x,y); //È¡·´ºÅ char dot = cir[y][x]; if(dot=='o') { partPostfix="-"; partPostfix.append(getPostfix(x-1,y)); } else if(dot==')') { partPostfix="&"; partPostfix.append(getPostfix(x-2,y-1)); partPostfix.append(getPostfix(x-2,y+1)); } else if(dot=='>') { partPostfix="|"; partPostfix.append(getPostfix(x-2,y-1)); partPostfix.append(getPostfix(x-2,y+1)); } else { //ÕÒµ½ÊäÈëÖµ partPostfix.erase(); stringstream ss; ss.clear(); ss<<dot; ss>>partPostfix; } return partPostfix; } void goEnd(int &x,int &y) { //±ê¼ÇÄ¿µÄµØ int cangoX=x,cangoY=y; //Ö±µ½ÕÒµ½ºó׺±í´ïʽÖеÄÔªËØ while(1) { //Ïò×óÒƶ¯ while(cir[y][x-1]=='-') { x--; cangoX = x-1; } //ÈôÊÇ'+',Ôò¼ÌÐø if(cir[cangoY][cangoX]=='+') { //ÏòÉÏ x=cangoX; while(cir[y-1][x]=='|') { y--; cangoY=y-1; } //ÏòÉÏÕýÈ· if(cangoY!=y) { y=cangoY; //Óöµ½×ªÕÛµã,¼ÌÐø if(cir[cangoY][x]=='+') { continue; } //ÕÒµ½,·µ»Ø else { return; } } //Ó¦¸ÃÏòÏ else { //¼ÈȻȷ¶¨ÏòÏÂ,¾Í×ßµ½Í· while(cir[y++][x]!='|'){} //Èô½ÚµãΪ'+',¼ÌÐø if(cir[y][x]=='+') { continue; } //·ñÔòÕÒµ½,·µ»Ø else { return; } } } //Èô²»ÊÇ'+',ÔòÕÒµ½,·µ»Ø else { x=cangoX; return; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator