当前位置:   article > 正文

CCF-CSP 202303-3 LDAP(待更)_ccf202303星际网络

ccf202303星际网络

题目链接

题目非常长,但还没有到完全看不懂的地步,即给你一些匹配表达式,让你输出对应的用户DN即可

该题,我就想奔着40分去的,因为40分只是符合EASY_EXPR即简单的匹配表达式,它只包含一个逻辑符号和两个括号内的简单式子如

&(1:2)(2:3)

数据结构上我选择vector与pair进行存储如下

 

因为如果只是满足EASY_EXPR,那么可能的情况会比较少,因此完全可以使用if将所有情况列出来,具体实现如下(不知为何0分)

  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. #include<set>
  5. using namespace std;
  6. int n, m;
  7. typedef struct Node {
  8. int attr, value;
  9. }Node;
  10. vector<pair<int, vector<Node> > >arr;
  11. vector<int> fun1(string exp) {//得到:符号匹配用户的DN
  12. int key = exp[0] - 48, v = exp[2] - 48;
  13. vector<int>res;A
  14. for (int i = 0; i < n; i++) {
  15. pair<int, vector<Node> >per = arr[i];
  16. int curDN = per.first;
  17. vector<Node>temp = per.second;
  18. int len = temp.size();
  19. for (int j = 0; j < len; j++) {
  20. if (temp[j].attr == key && temp[j].value == v) {
  21. res.push_back(curDN);
  22. break;
  23. }
  24. }
  25. }
  26. return res;
  27. }
  28. vector<int> fun2(string exp) {//得到~符号匹配用户的DN
  29. int key = exp[0] - 48, v = exp[2] - 48;
  30. vector<int>res;
  31. for (int i = 0; i < n; i++) {
  32. pair<int, vector<Node> >per = arr[i];
  33. int curDN = per.first;
  34. vector<Node>temp = per.second;
  35. int len = temp.size();
  36. for (int j = 0; j < len; j++) {
  37. if (temp[j].attr == key && temp[j].value != v) {
  38. res.push_back(curDN);
  39. break;
  40. }
  41. }
  42. }
  43. return res;
  44. }
  45. int main() {
  46. cin >> n;
  47. vector<Node>temp;
  48. for (int i = 1; i <= n; i++) {
  49. int DN, count_attr, attr, value;
  50. temp.clear();
  51. cin >> DN >> count_attr;
  52. for (int j = 1; j <= count_attr; j++) {
  53. cin >> attr >> value;
  54. temp.push_back({ attr,value });
  55. }
  56. arr.push_back(make_pair(DN, temp));
  57. }
  58. cin >> m;
  59. while (m--) {
  60. vector<int>ans;
  61. ans.clear();
  62. string exp;
  63. cin >> exp;
  64. if (exp[0] == '&') {
  65. string sub1 = exp.substr(2, 3);
  66. string sub2 = exp.substr(7, 3);
  67. vector<int>res1, res2;
  68. set<int>st;
  69. if (sub1[1] == ':') {
  70. res1 = fun1(sub1);
  71. }
  72. else if (sub1[1] == '~') {
  73. res1 = fun2(sub1);
  74. }
  75. if (sub2[1] == ':') {
  76. res2 = fun1(sub2);
  77. }
  78. else if (sub2[1] == '~') {
  79. res2 = fun2(sub2);
  80. }
  81. //找到res1与res2共同拥有的部分
  82. int len1 = res1.size(),len2=res2.size();
  83. for (int i = 0; i < len1; i++) {
  84. st.insert(res1[i]);
  85. }
  86. for (int j = 0; j < len2; j++) {
  87. if (st.count(res2[j])) {
  88. ans.push_back(res2[j]);
  89. }
  90. }
  91. }
  92. else if (exp[0] == '|') {
  93. string sub1 = exp.substr(2, 3);
  94. string sub2 = exp.substr(7, 3);
  95. vector<int>res1, res2;
  96. set<int>st;
  97. if (sub1[1] == ':') {
  98. res1 = fun1(sub1);
  99. }
  100. else if (sub1[1] == '~') {
  101. res1 = fun2(sub1);
  102. }
  103. if (sub2[1] == ':') {
  104. res2 = fun1(sub2);
  105. }
  106. else if (sub2[1] == '~') {
  107. res2 = fun2(sub2);
  108. }
  109. //找到res1与res2拥有的部分去重加入到ans中
  110. int len1 = res1.size(), len2 = res2.size();
  111. for (int i = 0; i < len1; i++) {
  112. st.insert(res1[i]);
  113. }
  114. for (int j = 0; j < len2; j++) {
  115. st.insert(res2[j]);
  116. }
  117. for (auto i = st.begin(); i != st.end(); i++) {
  118. ans.push_back(*i);
  119. }
  120. }
  121. else if(exp.length()==3){
  122. if (exp[1] == ':') {
  123. ans = fun1(exp);
  124. }
  125. else if (exp[1] == '~') {
  126. ans = fun2(exp);
  127. }
  128. }
  129. int len = ans.size();
  130. for (int i = 0; i < len; i++) {
  131. if (i == 0) {
  132. cout << ans[i];
  133. }
  134. else {
  135. cout << " " << ans[i];
  136. }
  137. }
  138. cout << endl;
  139. }
  140. return 0;
  141. }

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/215733
推荐阅读
相关标签
  

闽ICP备14008679号