Pagini recente » Cod sursa (job #1643819) | Cod sursa (job #2990286) | Cod sursa (job #479752) | Cod sursa (job #652995) | Cod sursa (job #2320294)
#include <fstream>
#include <cstring>
using namespace std;
int const NM = 1003;
char init [NM] , s [NM];
bool v [10 + 'Z'];
ifstream f ("bool.in");
ofstream g ("bool.out");
bool exp ();
bool term ();
bool fact ();
int p;
bool exp (){
bool sum = term ();
while (s [p] == 'o'){
++ p;
sum = sum | term ();
}
return sum;
}
bool term (){
bool prod = fact ();
while (s [p] == 'a'){
if (s [p] == 'a'){
++ p;
prod = prod & fact ();
}
}
return prod;
}
bool fact (){
bool x = true , val = false;
while (s [p] == 'n'){
x = false;
++ p;
}
if (s [p] == '('){
++ p;
val = exp ();
++ p;
return x ? val : ! val;
}
if (s [p] <= 'Z' + 2 && s [p] >= 'A')
val = v [s [p]] , ++ p;
return x ? val : ! val;
}
int main()
{
v ['Z' + 1] = true;
f . getline (init , NM);
int l = strlen (init) , l2 = 0;
while (p < l){
if (init [p] == 'A' && init [p + 1] == 'N')
s [l2] = 'a' , p += 3 , ++ l2;
if (init [p] == 'N' && init [p + 1] == 'O')
s [l2] = 'n' , p += 3 , ++ l2;
if (init [p] == 'O' && init [p + 1] == 'R')
s [l2] = 'o' , p += 2 , ++ l2;
if (init [p] == 'T' && init [p + 1] == 'R')
s [l2] = 'Z' + 1 , p += 4 , ++ l2;
if(init [p] == 'F' && init [p + 1] == 'A')
s [l2] = 'Z' + 2 , p += 5 , ++ l2;
if (init [p] != ' ')
s [l2] = init [p] , ++ l2;
++ p;
}
p = 0;
int t;
f >> t;
f . get ();
while (t --){
char c = f . get ();
v [c] = ! v [c];
p = 0;
g << exp ();
}
return 0;
}