计算机软件能力认证考试系统
20分:
#include<bits/stdc++.h>
using namespace std;
const int N=440;
int n,m,q,nv,no,nn,ns,ng;
struct Node
{string name;map<string,int>op;map<string,int>res_kind;map<string,int>res_name;
}role[N];
map<string,string>mp;
int main()
{scanf("%d %d %d",&n,&m,&q);for(int i=0;i<n;i++){cin>>role[i].name;scanf("%d",&nv);while(nv--){string s;cin>>s;}scanf("%d",&no);while(no--){string s;cin>>s;}scanf("%d",&nn);while(nn--){string s;cin>>s;}}string s1,s2,s3;for(int i=0;i<m;i++){cin>>s1>>ns>>s2>>s3;}for(int i=0; i<q; i++){string s,str1,str2,str3;cin>>s>>ng;string ss;cin>>ss;cin>>str1>>str2>>str3;if(s2=="u"){if(s3==s)printf("1\n");elseprintf("0\n");}else if(s2=="g"){if(s3==ss)printf("1\n");elseprintf("0\n");}}return 0;
}
100分:
需要注意提速之后,scanf与cin不能同时用
#include<iostream>
#include<vector>
#include<set>
#include<unordered_map>
using namespace std;
#pragma GCC optimize(2)struct User{string name;set<string> op;set<string> cat;set<string> list;
};
// 记录某些用户或组关联了哪些角色
// 实际上组和用户没必要区分,统一看作用户
unordered_map<string, vector<int>> to_users;int main(){ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);//提速,cin与scnaf不能同时用int n, m, q;cin >> n >> m >> q;vector<User> users(n);// Usersstring tmp;for(int i = 0; i < n; i ++){cin >> tmp;users[i].name = tmp;int nv, no, nn;// operationscin >> nv;while(nv--){cin >> tmp;users[i].op.insert(tmp);}// categorycin >> no;while(no--){cin >> tmp;users[i].cat.insert(tmp);}// listcin >> nn;while(nn--){cin >> tmp;users[i].list.insert(tmp);}}// 将用户或组绑定已有的角色while(m--){// cin >> tmp;int idx = -1;for(int i = 0; i < users.size(); i ++){if(users[i].name == tmp){idx = i;break;}}int ns;cin >> ns;string t1, t2;while(ns--){cin >> t1 >> t2;// push_back的是角色在users数组中的下标// 把用户和组都看做成用户,不区分身份,因此t1没用to_users[t2].push_back(idx);}}while(q--){cin >> tmp;int ng;cin >> ng;vector<string> group;// 加入关联的用户组(包含自己以及关联的用户和组)group.push_back(tmp);while(ng--) {cin >> tmp;group.push_back(tmp);}// check tmp1 tmp2 tmp3string tmp1, tmp2, tmp3;cin >> tmp1 >> tmp2 >> tmp3;bool flag1 = false, flag2 = flag1, flag3 = flag1;// 之后就是看组中这些用户关联的角色们是否有权限了// 满足一个就break,否则就重置三个flagfor(int i = 0; i < group.size(); i ++){int n = to_users[group[i]].size();for(int j = 0; j < n; j ++){if(users[to_users[group[i]][j]].op.count(tmp1) || users[to_users[group[i]][j]].op.count("*")) flag1 = true;if(users[to_users[group[i]][j]].cat.count(tmp2) || users[to_users[group[i]][j]].cat.count("*")) flag2 = true;if(users[to_users[group[i]][j]].list.size() == 0) flag3 = true;else{if(users[to_users[group[i]][j]].list.count(tmp3))flag3 = true;}if(flag1 && flag2 && flag3) break;else{flag1 = false;flag2 = flag1;flag3 = flag1;}}if(flag1 && flag2 && flag3) break;}if(flag1 && flag2 && flag3) cout << 1 << endl;else cout << 0 << endl;}
}