CCF CSP 202303-3 LDAP题解

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

一道很简单的题,主要是看到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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值