Pagini recente » Cod sursa (job #2272757) | Cod sursa (job #2148240) | Cod sursa (job #1328584) | Cod sursa (job #36766) | Cod sursa (job #3268736)
#include <fstream>
using namespace std;
const int DMAX = 1005;
char S[DMAX], *p;
int V[26]; ///Initial toate variabilele au valoarea FALSE (i.e. 0)
ifstream f("bool.in");
ofstream g("bool.out");
int expresie();
int termen();
int factor();
int expresie()
{
int r = termen();
while(*p == 'O' && *(p + 1) == 'R')
{
p += 3;
r |= termen();
}
return r;
}
int termen()
{
int r = factor();
while(*p == 'A' && *(p + 1) == 'N' && *(p + 2) == 'D')
{
p += 4;
r &= factor();
}
return r;
}
int factor()
{
int r;
if(*p == '(')
{
p++;
r = expresie();
p++;
}
else
if(*p == 'N' && *(p + 1) == 'O' && *(p + 2) == 'T')
{
p += 4;
r = !factor();
}
else
if(*p == 'T' && *(p + 1) == 'R' && *(p + 2) == 'U' && *(p + 3) == 'E')
{
p += 5;
r = 1;
}
else
if(*p == 'F' && *(p + 1) == 'A' && *(p + 2) == 'L' && *(p + 3) == 'S' && *(p + 4) == 'E')
{
p += 6;
r = 0;
}
else
{
r = V[*p - 'A'];
p += 2;
}
return r;
}
int main()
{
int N;
char c;
f.getline(S, DMAX);
f >> N;
f.get();
while(N--)
{
f.get(c);
V[c - 'A'] ^= 1;
p = S;
g << expresie();
}
f.close();
g.close();
return 0;
}