一道很简单的题,主要是看到BNF文法我就想写Parser,看见逻辑运算符就想写短路运算。然后浪费了很多时间。使用了类似解释器的结构,好像比一般用集合运算写快,但是时间限制是14s,所有没有任何作用。
`
//
// Created by 11067 on 2023/5/11.
//
#include <cstdio>
#include <unordered_map>
#include <set>
using namespace std;
enum class InstrType {
JS,
JNS,
SEQ,
SNE
};
struct Instr {
InstrType type;
int opr;
int value;
};
Instr instrs[1000];
int pc;
int prog_length;
struct Record {
unordered_map<int, int> attributes;
int dn;
} records[2500];
//parse query
char buffer[2005];
int current;
int number() {
int n = 0;
while (buffer[current] >= '0' && buffer[current] <= '9') {
n *= 10;
n += buffer[current] - '0';
current++;
}
return n;
}
void expr();
void base_expr() {
int attribute = number();
char op = buffer[current++];
int value = number();
instrs[pc++] = Instr{op == ':' ? InstrType::SEQ : InstrType::SNE, attrib

这是一篇关于CCF CSP中202303-3 LDAP题目的解析,作者分享了在解决过程中使用解释器结构的心得,虽然方法快速,但由于时间限制未能体现出优势。

5761

被折叠的 条评论
为什么被折叠?



