Pagini recente » Cod sursa (job #2941424) | Cod sursa (job #471291) | Cod sursa (job #1125366) | Cod sursa (job #2821953) | Cod sursa (job #2600891)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bool.in");
ofstream out("bool.out");
/// NOT > AND > OR
string s;
int n,i;
bool v[30];
int myor();
int myand();
int mynot();
int expresie();
int myor(){
int raspuns = myand();
while(s[i] == ' ')
i++;
while(i + 1 < n && s[i] == 'O' && s[i + 1] == 'R'){
i += 2;
int altceva = myand();
raspuns = raspuns or altceva;
}
return raspuns;
}
int myand(){
int raspuns = mynot();
while(s[i] == ' ')
i++;
while(i + 2 < n && s[i] == 'A' && s[i + 1] == 'N' && s[i + 2] == 'D'){
i += 3;
int altceva = mynot();
raspuns = raspuns & altceva;
}
return raspuns;
}
int mynot(){
int raspuns = expresie();
while(s[i] == ' ')
i++;
while(i + 2 < n && s[i] == 'N' && s[i + 1] == 'O' && s[i + 2] == 'T'){
i += 3;
int altceva = expresie();
raspuns = !altceva;
}
return raspuns;
}
int expresie(){
int raspuns = 0;
while(s[i] == ' '){
i++;
}
if(i < n){
if(s[i] == '('){
i++;
raspuns = myor();
i++;
}else{
if(isalpha(s[i])){
if((i == 0 && !isalpha(s[i + 1])) || (i == n - 1 && !isalpha(s[i - 1]))
|| (!isalpha(s[i - 1]) && !isalpha(s[i + 1]))){
char c = s[i];
raspuns = v[c - 'A'];
i++;
//cout<<c<<" ";
}
}
}
}
return raspuns;
}
int main()
{
getline(in,s);
n = s.size();
int chestii;
in>>chestii;
/// B or A
for(int a = 1; a <= chestii; a++){
char caracter;
in>>caracter;
if(!v[caracter - 'A'])
v[caracter - 'A'] = 1;
else
v[caracter - 'A'] = 0;
i = 0;
out<<myor();
}
return 0;
}