Pagini recente » Cod sursa (job #1331214) | Cod sursa (job #1565659) | Cod sursa (job #315730) | Cod sursa (job #2795943) | Cod sursa (job #1497472)
#include <stdio.h>
#include <stdlib.h>
#define MAXN 1000
#define MAXC 26
char v[MAXN+2];
int vf[MAXC],poz,n,i;
inline int numar(){
int nr;
if(v[poz]=='T'&&v[poz+1]=='R'){
nr=1;
poz+=4;
}
if(v[poz]=='F'&&v[poz+1]=='A'){
nr=0;
poz+=5;
}
if(v[poz+1]<'A'||v[poz+1]>'Z'){
nr=vf[v[poz]-'A'];
poz++;
}
return nr;
}
int fact(){
int nr;
if(v[poz]>='A'&&v[poz]<='Z'&&((v[poz]=='N'&&v[poz+1]!='O')||(v[poz+1]<'A'||v[poz+1]>'Z')||v[poz]!='N')){
nr=numar();
blanc();
}
else
if(v[poz]=='('){
poz++;
blanc();
nr=E();
poz++;
blanc();
}
else
if(v[poz]=='N'&&v[poz+1]=='O'){
poz+=3;
blanc();
nr=!fact();
}
return nr;
}
inline int term(){
int nr,x;
nr=fact();
while(v[poz]=='A'&&v[poz+1]=='N'){
poz+=3;
blanc();
x=fact();
nr=(nr&&x);
}
return nr;
}
inline int E(){
int nr,x;
nr=term();
while(v[poz]=='O'&&v[poz+1]=='R'){
poz+=2;
blanc();
x=term();
nr=(nr||x);
}
return nr;
}
inline void blanc(){
while(poz<n&&v[poz]==' ')
poz++;
}
int main(){
FILE*fi,*fout;
int t;
char a;
fi=fopen("bool.in" ,"r");
fout=fopen("bool.out" ,"w");
a=fgetc(fi);
n=0;
while(a!='\n'){
v[n++]=a;
a=fgetc(fi);
}
a=fgetc(fi);
t=0;
while(a>='0'&&a<='9'){
t=t*10+a-'0';
a=fgetc(fi);
}
a=fgetc(fi);
for(i=0;i<t;i++){
poz=0;
blanc();
vf[a-'A']=!vf[a-'A'];
fprintf(fout,"%d" ,E());
a=fgetc(fi);
}
fclose(fi);
fclose(fout);
return 0;
}