Pagini recente » Cod sursa (job #2246682) | Cod sursa (job #1659902) | Cod sursa (job #2557858) | Borderou de evaluare (job #553302) | Cod sursa (job #790346)
Cod sursa(job #790346)
#include <cstdio>
#include <cstring>
using namespace std;
const int MaxL = 1010;
char String[MaxL+5], *p;
bool Value[27];
inline void Increment(int V) {
for (p += V; *p == ' '; ++p);
}
inline bool True() {
if (*p == 'T' && *(p+1) == 'R') {
Increment(4);
return true;
}
return false;
}
inline bool False() {
if (*p == 'F' && *(p+1) == 'A') {
Increment(5);
return true;
}
return false;
}
inline bool Or() {
if (*p == 'O' && *(p+1) == 'R') {
Increment(2);
return true;
}
return false;
}
inline bool And() {
if (*p == 'A' && *(p+1) == 'N') {
Increment(3);
return true;
}
return false;
}
inline bool Not() {
if (*p == 'N' && *(p+1) == 'O') {
Increment(3);
return true;
}
return false;
}
bool Factor();
bool Term();
bool Expression();
bool Factor() {
if (*p == '(') {
Increment(1);
bool E = Expression();
Increment(1);
return E;
}
if (Not())
return !Factor();
if (True())
return true;
if (False())
return false;
bool V = Value[*p - 'A'];
Increment(1);
return V;
}
bool Term() {
bool F = Factor();
while (And())
F &= Factor();
return F;
}
bool Expression() {
bool T = Term();
while (Or())
T |= Term();
return T;
}
int main() {
freopen("bool.in", "r", stdin);
freopen("bool.out", "w", stdout);
fgets(String, MaxL, stdin);
String[strlen(String)] = '\0';
int N; scanf("%d\n", &N);
for (; N; --N) {
char V; scanf("%c", &V);
Value[V-'A'] ^= 1;
p = String;
printf("%d", Expression());
}
printf("\n");
return 0;
}