ccf 201612-3 权限查询
ccf 201612-3 权限查询
解题思路:
建立一个二维矩阵存储权限和角色
还差30分emmm
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
const int maxn = +;
const int maxq = + ;
map<string,int> cl;///权限名称到最高权限级别的映射
map<string,int> cn;//权限名称到数组下标的转换
map<string,int> rn;//角色名称到数组下标的转换
map<string,int> un;//用户名称到数组下标的转换
int rc[maxn][maxn];///rc[i][j]表示当前角色i拥有的权限j的最高等级
bool ur[maxn][maxn];///用户i是否有 角色j
int main()
{
char str[maxq];
int p,r,u,q;
cin>>p;
for(int i=;i<p;i++)
{
cin>>str;
char *find = strchr(str,':');
if(find == NULL)//无等级权限
{
cl[str] = -;
cn[str] = i;
} else{
int len = find - str;
char c[maxn];
int j = ;
for(j=;j<len;j++)
{
c[j] = str[j];
}
c[j] = '\0';
int num = ;
for(j=len+;j<strlen(str);j++)
{
num = num* + (str[j] - '');
}
cl[c] = num;
cn[c] = i;
}
}
cin>>r;//描述角色
for(int i=;i<r;i++)
for(int j=;j<p;j++)
rc[i][j] = -;
for(int i=;i<r;i++)
{
char str[maxn];
cin>>str;
rn[str] = i;
int s;
cin>>s;
for(int j=;j<s;j++){//读入角色拥有的权限
char c[maxn];
cin>>c;
char *find = strchr(c,':');
if(find == NULL){
//无等级权限
rc[rn[str]][cn[c]] = -;
}else{
int len = find - c;
char temp[maxn];
int j = ;
for(j=;j<len;j++)
{
temp[j] = c[j];
}
temp[j] = '\0';
int num = ;
for(j=len+;j<strlen(c);j++)
{
num = num* + (c[j] - '');
}
rc[rn[str]][cn[temp]] = num;
}
}
} cin>>u;//用户
memset(ur,false,sizeof(ur));
for(int i=;i<u;i++)
{
char str[maxn];
cin>>str;
un[str] = i;
int s;
cin>>s;
for(int j=;j<s;j++)
{
char c[maxn];
cin>>c;
ur[un[str]][rn[c]] = true;
}
} cin>>q;
for(int i=;i<q;i++)
{
char user[maxn],c[maxn];
cin>>user>>c;
char *find = strchr(c,':');
int num = ;char temp[maxn];
if(find == NULL){
map<string,int>::iterator iter = cn.find(c);
if(iter == cn.end())
{
cout<<"flase"<<endl;
continue;
}
iter = un.find(user);
if(iter == un.end())
{
cout<<"false"<<endl;
continue;
}
}else{
int len = find - c;
int j = ;
for(j=;j<len;j++)
{
temp[j] = c[j];
}
temp[j] = '\0'; map<string,int>::iterator iter = cn.find(temp);
if(iter == cn.end())
{
cout<<"flase"<<endl;
continue;
}
for(j=len+;j<strlen(c);j++)
{
num = num* + (c[j] - '');
}
iter = un.find(user);
if(iter == un.end())
{
cout<<"false"<<endl;
continue;
}
} if(find ==NULL && cl[c] == -)
{
bool flag = false;
for(int j=;j<r;j++)//便利所有的角色
{
if(ur[un[user]][j])
{
if(rc[j][cn[c]] == -)
{
cout<<"true"<<endl;
flag = true;
break;
}
}
}
if(!flag) cout<<"false"<<endl;
}
else if(find ==NULL && cl[c] != -){
//有等级权限,且查询等级
bool flag = false;
int max = ;
for(int j=;j<r;j++)//便利所有的角色
{
if(ur[un[user]][j])
{
if(rc[j][cn[c]] != -)
{
if(rc[j][cn[c]] > max) max = rc[j][cn[c]];
flag = true;
}
}
}
if(!flag) cout<<"false"<<endl;
else cout<<max<<endl;
}
else if(find != NULL){ bool flag = false;
for(int j=;j<r;j++)//便利所有的角色
{
if(ur[un[user]][j])
{
if(rc[j][cn[temp]] >= num)
{
cout<<"true"<<endl;
flag = true;
break;
}
}
}
if(!flag) cout<<"false"<<endl;
}
else{
cout<<"false"<<endl;
}
} return ;
}

ccf 201612-3 权限查询的更多相关文章
- CCF CSP 201612-3 权限查询
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201612-3 权限查询 问题描述 授权 (authorization) 是各类业务系统不可缺 ...
- CCF 权限查询(模拟)
试题编号: 201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统 ...
- 组合权限查询 SQL,UniGUI
组合权限查询 SQL,UniGUI: name ,View, New, Edit, Dele 表 获取 name 的 授权. 项目 1 0 0 ...
- linux系统下创建oracle表空间和用户权限查询
创建用户和表空间: 1.登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切换成oracle用户) 2.以sysdba方式来打开sqlplus,命令 ...
- CCF CSP 201709-3 JSON查询
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201709-3 JSON查询 问题描述 JSON (JavaScript Object Not ...
- CSP 201612-3 权限查询 【模拟+STL】
201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统用户通过授权 ...
- PostgreSQL的权限查询
查看哪些用户对表sns_log_member_b_aciton有哪些权限: sns_log=> \z sns_log_member_b_aciton Access privileges Sche ...
- Oracle 权限查询
查看当前用户权限:SQL> select * from session_privs; 查询某个用户被赋予的系统权限. Select * from user_sys_privs; 或者: sele ...
- Mysql 登录及用户切换、用户权限查询
启动mysql: 方法一:net start mysql(或者是其他服务名) 方法二:在windows下启动MySQL服务 MySql安装目录:"d:\MySql\" 进入命令行输 ...
随机推荐
- css样式小结(持续更新...)
1.手写table的border,显示空白间隔,而不是想要的样式,需要添加下面的样式处理 table{ border-collapse:collapse; } 2.移动端输入框效果,去掉高亮边框, i ...
- 用Buildout来构建Python项目
用Buildout来构建Python项目 什么是Buildout (Remixed by Matt Hamilton, original from http://xkcd.com/303) Bui ...
- c++中cin和cout的用法
cin和cout是c++中的标准输入输出流. 一.cin cin的一般用法: cin>>变量a>>变量b>>变量c; cin会自动辨别变量的类型,如a可以是char ...
- Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)
Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...
- 自然语言处理(三) 预训练模型:XLNet 和他的先辈们
预训练模型 在CV中,预训练模型如ImagNet取得很大的成功,而在NLP中之前一直没有一个可以承担此角色的模型,目前,预训练模型如雨后春笋,是当今NLP领域最热的研究领域之一. 预训练模型属于迁移学 ...
- POJ 1741 单次询问树上距离<=K的点对数 点分治
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; ; ], ...
- hutools之批量更新
public class HutoolTest { private static DataSource dataSource = DSFactory.get(); //读取默认路径下的配置文件,数据库 ...
- spark 三种数据集的关系(二)
一个Dataset是一个分布式的数据集,而且它是一个新的接口,这个新的接口是在Spark1.6版本里面才被添加进来的,所以要注意DataFrame是先出来的,然后在1.6版本才出现的Dataset,提 ...
- Hadoop-No.7之行键
和哈希表类比,HBase中的行键类似于哈希表中的键.要构造一个良好的HBase模式,关键之一就是选择一个合适的行键. 1 记录检索 行键是HBase中检索记录所使用的键.HBase记录含有的列在数量上 ...
- java 日期增加
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public cl ...