Created
February 27, 2019 15:15
-
-
Save cyyself/e926af5a8204b81fc89b2303b3176868 to your computer and use it in GitHub Desktop.
离散数学老师的作业,欢迎Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
'A'-'Z'表示命题 | |
!表示非 | |
&表示合取 | |
|表示析取 | |
A@B表示如果A,那么B | |
A#B表示双条件 | |
()表示优先级 | |
*/ | |
#include <bits/stdc++.h> | |
using namespace std; | |
string s; | |
int dfs(int ptr) { | |
bool pre_not = false; | |
while (true) { | |
if (ptr >= s.length()) return -1; | |
if ( (s[ptr] >= 'A' && s[ptr] <= 'Z') || s[ptr] == '!' || s[ptr] == '(') { | |
if (s[ptr] == '!') pre_not ^= 1; | |
else { | |
if (s[ptr] == '(') { | |
int ret = dfs(ptr+1); | |
if (ret == -1) return -1; | |
ptr = ret; | |
} | |
if (ptr + 1 >= s.length()) return -1; | |
if (s[ptr+1] == ')') return ptr + 1; | |
if (s[ptr+1] != '&' && s[ptr+1] != '|' && s[ptr+1] != '@' && s[ptr+1] != '#') return -1; | |
ptr ++; | |
pre_not = false; | |
} | |
} | |
else return -1; | |
ptr ++; | |
} | |
} | |
int main() { | |
getline(cin,s); | |
s += ')'; | |
if (dfs(0) == s.length() - 1) printf("OK\n"); | |
else printf("ERROR\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment