为什么!!!有思路但是写不出!!!
#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;
}