https://onlinejudge.u-aizu.ac.jp/challenges/sources/JAG/Prelim/2883
前提知識
解法
https://onlinejudge.u-aizu.ac.jp/solutions/problem/2883/review/2994318/hamayanhamayan/C++14
構文解析を頑張る。
実装例として下に載せておく。
string S, P; //--------------------------------------------------------------------------------------------------- int i, a, b, c, d; int f() { if (S[i] == '[') { i++; int l, r, res; if (S[i] == '+') { i++; l = f(); r = f(); res = l | r; } else if (S[i] == '*') { i++; l = f(); r = f(); res = l & r; } else { i++; l = f(); r = f(); res = l ^ r; } i++; return res; } int res; if (S[i] == 'a') res = a; else if (S[i] == 'b') res = b; else if (S[i] == 'c') res = c; else res = d; i++; return res; } //--------------------------------------------------------------------------------------------------- void _main() { while (cin >> S) { if (S == ".") return; cin >> P; i = 0; a = P[0] - '0'; b = P[1] - '0'; c = P[2] - '0'; d = P[3] - '0'; int ha = f(); int cnt = 0; rep(j, 0, 10000) { i = 0; a = j / 1000; b = (j / 100) % 10; c = (j / 10) % 10; d = j % 10; if (ha == f()) cnt++; } printf("%d %d\n", ha, cnt); } }