Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

#define MAX_NUM 2
#define MAX_CH 10
#define MAX_N 1200

string S, T;
char NUM[MAX_NUM + 1] = "01";
char CH[MAX_CH + 1] = "abcdefghij";
int TR[MAX_CH];
int CNT[MAX_N];

int Plus(int c1, int c2) {
	return max(c1, c2);
}
int kake(int c1, int c2) {
	return min(c1, c2);
}
int fukumi(int c1, int c2) {
	if (c1 == 1 && c2 == 0) {
		return 0;
	}
	return 1;
}

int calc2(string A2) {
	A2 = A2.substr(1, A2.size() - 1);
	if (A2.size() == 3) {
		int p1, p2;
		p1 = STOI(A2[0]);
		p2 = STOI(A2[2]);
		if (A2[1] == '+') {
			return Plus(p1, p2);
		}
		if (A2[1] == '*') {
			return kake(p1, p2);
		}
		if (A2[1] == '&') {
			return fukumi(p1, p2);
		}
	}
	else if (A2.size() == 4) {
		if (A2[0] == '-') {
			int p1, p2;
			p1 = STOI(A2[1]);
			p2 = STOI(A2[3]);
			if (A2[1] == '+') {
				return Plus(1 - p1, p2);
			}
			if (A2[1] == '*') {
				return kake(1 - p1, p2);
			}
			if (A2[1] == '&') {
				return fukumi(1 - p1, p2);
			}
		}
		if (A2[2] == '-') {
			int p1, p2;
			p1 = STOI(A2[0]);
			p2 = STOI(A2[3]);
			if (A2[1] == '+') {
				return Plus(p1, 1 - p2);
			}
			if (A2[1] == '*') {
				return kake(p1, 1 - p2);
			}
			if (A2[1] == '&') {
				return fukumi(p1, 1 - p2);
			}
		}
	}
	else {
		int p1, p2;
		p1 = STOI(A2[1]);
		p2 = STOI(A2[4]);
		if (A2[1] == '+') {
			return Plus(1 - p1, 1 - p2);
		}
		if (A2[1] == '*') {
			return kake(1 - p1, 1 - p2);
		}
		if (A2[1] == '&') {
			return fukumi(1 - p1, 1 - p2);
		}
	}
}

int STOI(char V) {
	if (V == '0') {
		return 0;
	}
	else {
		return 1;
	}
}

string TOSTR(int d) {
	if (d == 0) {
		return "0";
	}
	else {
		return "1";
	}
}

int calc(string Y) {
	for (int i = 0; i < MAX_N; i++) {
		CNT[i] = 0;
	}
	string Z = "", AA = "";

	while (Z.size() >= 2) {
		int L = 0, MN = 0;
		bool ok1 = false;
		Z = ""; AA = "";
		int pass2 = 0;
		int pass3 = -1;
		while (pass2 < Y.size()) {
			if (Y[pass2] == '(') {
				L++;
			}
			if (Y[pass2] == ')') {
				L++;
			}
			CNT[pass2] = L;
			pass2++;
			MN = max(MN, L);
		}
		for (int i = 0; i < Y.size(); i++) {
			if (CNT[i] == MN) {
				if (pass3 == -1) {
					pass3 = i;
				}
				AA += Y[i];
				if (i < Y.size() - 1) {
					if (Y[i + 1] == ')') {
						ok1 = false;
					}
				}
			}
			else {
				Z += Y[i];
			}
		}
		int ZSIZE = Z.size();
		Z = Z.substr(0, pass3) + TOSTR(calc2(AA)) + Z.substr(pass3, ZSIZE - pass3);
	}
	if (Z == "0") {
		return false;
	}
	else {
		return true;
	}
}

int power(int a, int b) {
	int res2 = 1;
	for (int i = 0; i < b; i++) {
		res2 *= a;
	}
	return res2;
}

bool solve(string U) {
	bool RES = true;
	string V = "";
	string V1 = "", V2 = "";
	string W1 = "", W2 = "";

	for (int i = 0; i < U.size(); i++) {
		if (U[i] == 'T') {
			V += '1';
			goto E;
		}
		else if (U[i] == '>') {
			//nanimo shinai.
		}
		else if (U[i] == 'F') {
			V += '0';
			goto E;
		}
		else if (i < U.size() - 1) {
			if (U.substr(i, 2) == "->") {
				V += '&';
				goto E;
			}
		}
		else {
			V += U[i];
		}
	E:;
	}

	int cnt1 = 0;
	for (int i = 0; i < V.size(); i++) {
		if (V[i] == '=') {
			cnt1 = 1;
		}
		else if (cnt1 == 0) {
			V1 += V[i];
		}
		else if (cnt1 == 1) {
			V2 += V[i];
		}
	}

	int pass1 = 0;
	while (pass1 < V1.size()) {
		if (V1[pass1] == '-') {
			int cnt2 = 0;
			while (V1[pass1] == '-') {
				cnt2++;
				pass1++;
			}
			if (cnt2 % 2 == 1) {
				W1 += '(';
				W1 += '-';
				W1 += V1[pass1];
				W1 += ')';
			}
			else {
				W1 += V1[pass1];
			}
			pass1++;
		}
		if (pass1 < V1.size()) {
			W1 += V1[pass1];
			pass1++;
		}
	}

	pass1 = 0;
	while (pass1 < V2.size()) {
		if (V2[pass1] == '-') {
			int cnt2 = 0;
			while (V2[pass1] == '-') {
				cnt2++;
				pass1++;
			}
			if (cnt2 % 2 == 1) {
				W2 += '(';
				W2 += '-';
				W2 += V2[pass1];
				W2 += ')';
			}
			else {
				W2 += V2[pass1];
			}
			pass1++;
		}
		if (pass1 < V2.size()) {
			W2 += V2[pass1];
			pass1++;
		}
	}

	string X1 = "", X2 = "";

	for (int i = 0; i < power(2, MAX_NUM); i++) {
		X1 = ""; X2 = "";
		for (int j = 0; j < MAX_NUM; j++) {
			int a1 = (i / power(2, j)) % 2;
			TR[j] = a1;
		}

		for (int j = 0; j < V1.size(); j++) {
			for (int k = 0; k < MAX_NUM; k++) {
				if (W1[j] == CH[k]) {
					X1 += NUM[TR[j]];
					goto F;
				}
			}
			X1 += W1[j];
		F:;
		}

		for (int j = 0; j < V2.size(); j++) {
			for (int k = 0; k < MAX_NUM; k++) {
				if (W2[j] == CH[k]) {
					X2 += NUM[TR[j]];
					goto G;
				}
			}
			X2 += W1[j];
		G:;
		}

		int res_1 = calc(X1);
		int res_2 = calc(X2);
		if (res_1 != res_2) {
			RES = false;
		}
	}
	return RES;
}

int main() {
	while (true) {
		cin >> S;
		if (S == "#") {
			break;
		}
		bool res = solve(S);
		if (res == true) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'int calc2(std::string)':
a.cc:34:22: error: 'STOI' was not declared in this scope
   34 |                 p1 = STOI(A2[0]);
      |                      ^~~~
a.cc:49:30: error: 'STOI' was not declared in this scope
   49 |                         p1 = STOI(A2[1]);
      |                              ^~~~
a.cc:63:30: error: 'STOI' was not declared in this scope
   63 |                         p1 = STOI(A2[0]);
      |                              ^~~~
a.cc:78:22: error: 'STOI' was not declared in this scope
   78 |                 p1 = STOI(A2[1]);
      |                      ^~~~
a.cc:90:1: warning: control reaches end of non-void function [-Wreturn-type]
   90 | }
      | ^