Cod sursa(job #2330707)
Utilizator | Data | 28 ianuarie 2019 19:39:21 | |
---|---|---|---|
Problema | Bool | Scor | 70 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 4.46 kb |
#include <bits/stdc++.h>
using namespace std;
char s[10005];
int op1(int nr1,int nr2,int c)
{
if(c==1)
{
return max(nr1,nr2);
}
if(c==2)return min(nr1,nr2);
return (nr1+1)%2;
}
int main()
{
freopen("bool.in","r",stdin);
freopen("bool.out","w",stdout);
fgets(s+1,1005,stdin);
int n=strlen(s+1);
s[n]=NULL;
--n;
int v[30],i;
for(i=1;i<=26;i++)v[i]=0;
int k;
char r[10005];
scanf("%d\n",&k);
fgets(r+1,1005,stdin);
int k1=strlen(r+1);
--k1;
for(int l=1;l<=k1;l++)
{
int poz=r[l]-'A'+1;
v[poz]++;
v[poz]%=2;
stack<int>st;
stack<int>op;
for(i=1;i<=n;i++)
{
if(s[i]==' ')continue;
if(s[i]=='T'&&s[i+1]=='R')
{
i+=3;
st.push(1);
continue;
}
if(s[i]=='F'&&s[i+1]=='A')
{
i+=4;
st.push(0);
continue;
}
if(s[i]>='A'&&s[i]<='Z'&&!(s[i+1]>='A'&&s[i+1]<='Z'))
{
st.push(v[s[i]-'A'+1]);
continue;
}
if(s[i]=='(')
{
op.push(0);
continue;
}
if(s[i]=='O'&&s[i+1]=='R')
{
if(op.empty())
{
op.push(1);
i++;
continue;
}
if(op.top()==0)
{
op.push(1);
i++;
continue;
}
i++;
if(op.top()<=2)
{
int nr2=st.top();
st.pop();
st.top()=op1(st.top(),nr2,op.top());
op.pop();
op.push(1);
continue;
}
st.top()=op1(st.top(),0,3);
op.pop();
op.push(1);
continue;
}
if(s[i]=='A'&&s[i+1]=='N')
{
i+=2;
if(op.empty())
{
op.push(2);
//i++;
continue;
}
if(op.top()<=1)
{
op.push(2);
//i++;
continue;
}
//i++;
if(op.top()==2)
{
int nr2=st.top();
st.pop();
st.top()=op1(st.top(),nr2,op.top());
continue;
}
st.top()=op1(st.top(),0,3);
op.pop();
op.push(2);
continue;
}
if(s[i]=='N'&&s[i+1]=='O')
{
i+=2;
if(op.empty())
{
op.push(3);
continue;
}
if(op.top()<=2)
{
op.push(3);
continue;
}
st.top()=op1(st.top(),0,3);
continue;
}
if(s[i]==')')
{
while(!op.empty())
{
if(op.top()==0)
{
op.pop();
break;
}
if(op.top()<=2)
{int nr2=st.top();
st.pop();
st.top()=op1(st.top(),nr2,op.top());}
else
st.top()=op1(st.top(),0,3);
op.pop();
}
}
}
while(!op.empty())
{
if(op.top()==0)
{
op.pop();
continue;
}
if(op.top()<=2)
{int nr2=st.top();
st.pop();
st.top()=op1(st.top(),nr2,op.top());}
else
st.top()=op1(st.top(),0,3);
op.pop();
}
printf("%d",st.top());
}
return 0;
}