| ||||||||||
| 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:怎么改成这样了还是OLE啊,大牛讲一下吧In Reply To:为什么一直OLE啊,请大家帮忙看看 Posted by:Fgnore at 2007-11-24 01:41:11 #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 i,j,cirCnt;
char temp[MAX];
int x0,y0;
while(cin.getline(temp,MAX-2))
{
memset(cir,' ',sizeof(cir));
strcpy(cir[1]+1,temp);
//cin [][]
cirCnt=2;
while(strcmp(cir[cirCnt-1]+1,"*"))
{
cin.getline(cir[cirCnt++]+1,MAX-2);
}
bool ok=false;
for(i=cirCnt-2;i>0;i--)
{
for(j=MAX-2;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);
cout<<postfix<<endl;
cin.getline(input,22);
while(strcmp(input,"*"))
{
cout<<getResult(postfix)<<endl;
cin.getline(input,22);
}
cout<<endl;
}
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];
//½øÈ¥ºÍ³öÈ¥µÄ'o'¶¼Òª¿¼ÂÇ
if(dot=='o')
{
partPostfix="-";
cir[y][x]='+';
partPostfix.append(getPostfix(x,y));
}
else if(dot==')')
{
partPostfix="&";
cir[y-1][x-2]='+';
cir[y+1][x-2]='+';
partPostfix.append(getPostfix(x-2,y-1));
partPostfix.append(getPostfix(x-2,y+1));
}
else if(dot=='>')
{
partPostfix="|";
cir[y-1][x-2]='+';
cir[y+1][x-2]='+';
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)
{
//Ö±µ½ÕÒµ½ºó׺±í´ïʽÖеÄÔªËØ
while(1)
{
//Ïò×óÒÆ¶¯
if(cir[y][x-1]!=' ')
{
while(cir[y][--x]=='-'){}
}
//ÈôÊÇ'+',Ôò¼ÌÐø
if(cir[y][x]=='+')
{
//ÏòÉÏ
if(cir[y-1][x]!=' ')
{
while(cir[--y][x]=='|'){}
}
//ÏòÏÂ
else
{
while(cir[++y][x]=='|'){}
}
//ÈôÊÇ'+',Ôò¼ÌÐø
if(cir[y][x]=='+') continue;
else return;
}
//Èô²»ÊÇ'+',ÔòÕÒµ½,·µ»Ø
else return;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator