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\" 进入命令行输 ...
随机推荐
- SSIS 初次接触 + 开发记录
第一次接触SSIS,昨天终于把一套流程走通,记一下流水. 1:安装 使用SSIS需要安装插件(VS 和Sql Server都需要另外安装). 自己使用的vs2017开发,官网有专门的 VS2017 安 ...
- 1.移动端自动化测试-知识笔记(面试必备,测试点,adb命令)
移动端测试: 移动应用,特性(功能) 满足 需求(产品文档,隐性需求) 一.App功能测试: 死活背下来1.业务逻辑正确性测试: 产品文档,隐性需求- 写成测试用例 2.兼容性测试: 1.系统版本 ...
- ChinaCock打印控件介绍-TCCFujitsuPrinter实现蓝牙针式打印
项目中遇到,要蓝牙针式打印机,用手机打印表单.感谢专家,对厂家提供的SDK进行了封装,实现利用Delphi开发出这一功能. 现在来看看,如何利用这一控件实现打印过程: procedure startS ...
- Oracle笔记(一) Oracle简介及安装
一.轨迹 二.Oracle简介 Oracle是现在全世界最大的数据库提供商,编程语言提供商,应用软件提供商,它的地位等价于微软的地位. Oracle在古希腊神话中被称为“神谕”,指的是上帝的宠儿,在中 ...
- 深圳即将启动首届「全国人工智能大赛」:超过 500 万大奖 & 政府资助,潜信息你读懂了吗!
人工智能加速“视频/视觉”发展,近期,深圳市即将迎来人工智能领域权威赛事之一——首届「全国人工智能大赛」(The First National Artificial Intelligence Chal ...
- Linux下python3的安装以及redis的使用
python3的安装 上传Python-3.5.2.tar.xz软件到 /server/tools 中 解压 :tar xf Python-3.5.2.tar.xz 编译安装cd Python-3 ...
- BZOJ 1015 并查集&连通块
很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过特殊的以太隧道互相直接或 ...
- Summer training #6
A:水.看0多还是1多就行 B:模拟二进制运算 ,,卡了好久 不应该 #include <bits/stdc++.h> #include <cstring> #include ...
- libusb_bulk_transfer 说明
libusb_bulk_transfer函数说明 API_EXPORTED int libusb_bulk_transfer(struct libusb_device_handle *dev_ha ...
- MyBatis: Invalid bound statement (not found)错误的可能原因
MyBatis: Invalid bound statement (not found)错误的可能原因 其他原因导致此问题解决参考: 1.检查 xml 文件所在 package 名称是否和 Mappe ...