Pagini recente » Cod sursa (job #1507617) | Cod sursa (job #1389615) | Cod sursa (job #1969921) | Cod sursa (job #1037201) | Cod sursa (job #2842332)
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
char s[1010];
bool f[200];
int i = 0;
bool expresieOR();
bool expresieAND();
bool expresieNOT();
bool constanta();
bool expresieOR()
{
bool r = expresieAND();
while (strcmp(strstr(s + i, "OR"), s + i) == 0)
{
i += 2;
if (s[i] == ' ')
i++;
r = r || expresieAND();
}
return r;
}
bool expresieAND()
{
bool r = expresieNOT();
while (strcmp(strstr(s + i, "AND"), s + i) == 0)
{
i += 3;
if (s[i] == ' ')
i++;
r = r && expresieNOT();
}
return r;
}
bool expresieNOT()
{
// B OR NOT C
bool r;
if (strcmp(strstr(s + i, "NOT"), s + i) == 0)
{
i += 3;
if (s[i] == ' ')
i++;
r = !(constanta());
}
else
r = constanta();
return r;
}
bool constanta()
{
bool r;
if (s[i] == '(')
{
i++;
r = expresieOR();
i++;
if (s[i] == ' ')
i++;
}
else if (strstr(s + i, "TRUE") && strcmp(strstr(s + i, "TRUE"), s + i) == 0)
{
i += 4;
if (s[i] == ' ')
i++;
r = true;
}
else if (strstr(s + i, "FALSE") && strcmp(strstr(s + i, "FALSE"), s + i) == 0)
{
i += 5;
if (s[i] == ' ')
i++;
r = false;
}
else
r = f[s[i]];
return r;
}
int main()
{
fin.getline(s, 1001);
int n;
fin >> n;
for (int k = 1; k <= n; k++)
{
char t;
fin >> t;
f[t] = !f[t];
fout << expresieOR();
}
return 0;
}