【Daily Code】CSP LDAP

在这里插入图片描述

为什么!!!有思路但是写不出!!!

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>

using namespace std;

vector<pair<int, vector<pair<int, int>>>> peo;
int n, m;

int find(string c, int l, int r)
{
    for (int i = l; i <= r; i++)
    {
        if (c[i] == ')')
            return i;
    }
    return -1;
}

int find_operand(string c, int l, int r)
{
    for (int i = l; i <= r; i++)
    {
        if (c[i] == '&' || c[i] == '|')
            return i;
    }
    return -1;
}

void find_peo(string c, int a, int b, vector<int> &res, int k)
{
    for (auto x : peo)
    {
        for (auto y : x.second)
        {
            if (y.first == a && y.second == b && k)
            {
                res.push_back(x.first);
            }
            else if (y.first == a && y.second != b && !k)
            {
                res.push_back(x.first);
            }
        }
    }
}

void deal_BASE_EXPR(string c, int l, int r, vector<int> &res)
{
    int oper = find_operand(c, l, r);
    string N1 = c.substr(l, oper - l);
    int tmp1 = stoi(N1);
    string N2 = c.substr(oper + 1, r - oper);
    int tmp2 = stoi(N2);
    if (oper == ':')
    {
        find_peo(c, tmp1, tmp2, res, 1);
    }
    else
    {
        find_peo(c, tmp1, tmp2, res, 0);
    }
}

void deal_ALL_EXPR(string c, int l, int r, vector<int> &res)
{
    if (c[l] == '&' || c[l] == '|')
    {
        // 确定EXPR1在c中的起始位置
        int l1 = l + 2, r1 = 0;
        r1 = find(c, l1, r) - 1;
        vector<int> res1, res2;
        deal_ALL_EXPR(c, l1, r1, res1);
        // 确定EXPR2在c中的起始位置
        int l2 = r1 + 3, r2 = 0;
        r2 = find(c, l2, r) - 1;
        deal_ALL_EXPR(c, l2, r2, res2);
        if (c[l] == '&')
        {
            // 两边都要有才能加入res
            for (auto x : res1)
            {
                if (count(res2.begin(), res2.end(), x))
                    res.push_back(x);
            }
        }
        else
        {
            for (auto x : res1)
            {
                res.push_back(x);
            }
            for (auto x : res2)
            {
                if (!count(res.begin(), res.end(), x))
                    res.push_back(x);
            }
        }
    }
    else
    {
        deal_BASE_EXPR(c, l, r, res);
    }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int DN, num;
        cin >> DN >> num;
        vector<pair<int, int>> tmp;
        for (int i = 0; i < num; i++)
        {
            int k, v;
            cin >> k >> v;
            tmp.push_back({k, v});
        }
        peo.push_back({DN, tmp});
    }

    cin >> m;
    vector<int> res;
    for (int i = 0; i < m; i++)
    {
        string in;
        cin >> in;
        int len = in.size();
        deal_ALL_EXPR(in, 0, len - 1, res);
    }

    for (auto x : res)
        cout << x << endl;
    int len = res.size();
    if (!len)
        cout << endl;

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值