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\" 进入命令行输 ...
随机推荐
- kali工具的总结
由于篇幅有限,只列举部分,ps:第一次发有什么不对的 还望各位大大指正 nc 瑞士军刀 [v1.10-41] 使用格式: nc [-参数] 主机名 端口[s] [端口] … 侦听入站: nc -l - ...
- 根文件系统ramdisk.image.gz && uramdisk.image.gz
1. 根文件系统镜像ramdisk.image.gz和uramdisk.image.gz 通常需要将文件系统输入到Nand Flash当中时,一般可以将根文件系统打包成uramdisk.image.g ...
- manjaro开机出现grub 解决办法
# 第一步:输入ls出现(hd0,msods1),(hd0,msdos5),(hd0,msods7)# 不同的电脑不一样,这是我电脑中的磁盘分区,和系统中的表示方法不一样,# linux中一般是/de ...
- 代码检查工具sonarqube介绍
SonarQube 是一款用于代码质量管理的开源工具,它主要用于管理源代码的质量.通过插件形式,可以支持众多计算机语言. 比如 java, C#, go,C/C++, PL/SQL,Cobol,Jav ...
- Sereja and Brackets CodeForces - 380C (线段树+分治思路)
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...
- Google Chrome Keyboard Shortcuts
Navigation To do this Press this Open a new window Ctrl + N Open a new tab Ctrl + T Open a new windo ...
- 生成静态libevent
INCLUDE C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include D:\vs2013\VC\include LIB C:\Prog ...
- 点击startup.bat启动tomcat出现乱码
找到tomcat目录下的/conf/logging.properties添加语句:java.util.logging.ConsoleHandler.encoding = GBK重启tomcat 问题解 ...
- 关于Spring MVC写的不错的几篇博客
关于Spring MVC写的不错的几篇博客 https://my.oschina.net/kolbe/blog/509810 https://www.cnblogs.com/sunniest/p/45 ...
- top命令经常用来监控linux的系统状况,比如cpu、内存的使用,程序员基本都知道这个命令。 按 q 退出
top命令经常用来监控linux的系统状况,比如cpu.内存的使用,程序员基本都知道这个命令. 按 q 退出