Mai intai trebuie sa te autentifici.
Cod sursa(job #1496625)
| Utilizator | Data | 5 octombrie 2015 11:58:23 | |
|---|---|---|---|
| Problema | Bool | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.65 kb |
#include <stdio.h>
using namespace std;
char s[10001], q=0;
bool val[30];
/// e = t OR t OR t
/// t=f AND f AND f AND f
/// f=(e)|variabila|NOT variabila
///NOT>AND>OR
bool E();
bool T();
bool F();
bool E()
{
bool raspuns=T();
while(s[q]=='O' && s[q+1]=='R')
{
q+=2;
bool tmp = T();
raspuns=(raspuns || tmp);
}
return raspuns;
}
bool T()
{
bool raspuns=F();
while(s[q]=='A' && s[q+1]=='N')
{
q+=3;
bool tmp = F();
raspuns=(raspuns && tmp);
}
return raspuns;
}
bool F()
{
bool raspuns = 0;
if(s[q]=='(')
{
q++;
raspuns = E();
q++;
return raspuns;
}
if(s[q]=='N' && s[q+1]=='O')
{
q+=3;
raspuns=F();
raspuns=!raspuns;
return raspuns;
}
if(s[q]=='T' && s[q+1]=='R')
{
q+=4;
return 1;
}
if(s[q]=='F' && s[q+1]=='A')
{
q+=5;
return 0;
}
if(val[s[q]-'A'] == 0)
{
q++;
return 0;
}
if(val[s[q]-'A'] == 1)
{
q++;
return 1;
}
}
int main()
{
FILE*fin=fopen("bool.in","r");
FILE*fout=fopen("bool.out","w");
char ch=fgetc(fin);
while(ch!='\n')
{
if(ch!=' ')
{
s[q++]=ch;
}
ch=fgetc(fin);
}
int n;
fscanf(fin,"%d\n", &n);
for(int i=1; i<=n; i++)
{
q=0;
char c;
fscanf(fin,"%c",&c);
val[c-'A']=!val[c-'A'];
fprintf(fout,"%d",E());
}
return 0;
}
