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\" 进入命令行输 ...
随机推荐
- 第十章、collections
目录 第十章.collections 一.OrderedDict方法 第十章.collections 一.OrderedDict方法 使用dict时,Key是无序的.在对dict做迭代时,我们无法确定 ...
- scroll js 原生
1.当前位置滚动: document.documentElement.scrollTop 当前位置: 有可能是0 window.scrollTo(,document.documentElement.s ...
- (备忘)Java数据类型中String、Integer、int相互间的转换
1.Integer转换成int的方法 Integer i; int k = i.intValue();即Integer.intValue(); 2.int转换成Integer int i; Integ ...
- 4.5. scrapy两大爬虫类_Spider
一:Spider Spider类定义了如何爬取某个(或某些)网站.包括了爬取的动作(例如:是否跟进链接)以及如何从网页的内容中提取结构化数据(爬取item). 换句话说,Spider就是您定义爬取 的 ...
- Linux ping route nslookup ifconfig arp traceroute
route -n 查看默认网关 ping -c 包个数 ping -s 包大小 host 目标主机 主机解析 nslookup 目标主机 arp -an 查看arp arp -s IP地 MA ...
- Python库整理
库名称简介 Chardet字符编码探测器,可以自动检测文本.网页.xml的编码. colorama主要用来给文本添加各种颜色,并且非常简单易用. Prettytable主要用于在终端或浏览器端构建格式 ...
- 返回的json数据中有属性为null的情况,报错 "message" : "Could not write JSON: Object is null
- Redux应用多人协作的思路和实现
先上Demo动图,效果如下: 基本思路 由于redux更改数据是dispatch(action),所以很自然而然想到以action作为基本单位在服务端和客户端进行传送,在客户端和服务端用数组来存放ac ...
- @Valid与@Validated
Spring Validation验证框架对参数的验证机制提供了@Validated(Spring's JSR-303规范,是标准JSR-303的一个变种),javax提供了@Valid(标准JSR- ...
- Spring Security 解决X-Frame-Options deny
错误信息: Refused to display 'https://github.com/hwclass/awesome-sound' in a frame because it set 'X-Fra ...