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 权限查询的更多相关文章

  1. CCF CSP 201612-3 权限查询

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201612-3 权限查询 问题描述 授权 (authorization) 是各类业务系统不可缺 ...

  2. CCF 权限查询(模拟)

    试题编号: 201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统 ...

  3. 组合权限查询 SQL,UniGUI

    组合权限查询 SQL,UniGUI: name ,View, New, Edit, Dele      表 获取 name 的 授权. 项目         1       0       0    ...

  4. linux系统下创建oracle表空间和用户权限查询

    创建用户和表空间: 1.登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切换成oracle用户) 2.以sysdba方式来打开sqlplus,命令 ...

  5. CCF CSP 201709-3 JSON查询

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201709-3 JSON查询 问题描述 JSON (JavaScript Object Not ...

  6. CSP 201612-3 权限查询 【模拟+STL】

    201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统用户通过授权 ...

  7. PostgreSQL的权限查询

    查看哪些用户对表sns_log_member_b_aciton有哪些权限: sns_log=> \z sns_log_member_b_aciton Access privileges Sche ...

  8. Oracle 权限查询

    查看当前用户权限:SQL> select * from session_privs; 查询某个用户被赋予的系统权限. Select * from user_sys_privs; 或者: sele ...

  9. Mysql 登录及用户切换、用户权限查询

    启动mysql: 方法一:net start mysql(或者是其他服务名) 方法二:在windows下启动MySQL服务 MySql安装目录:"d:\MySql\" 进入命令行输 ...

随机推荐

  1. 利用 Monitor.TryEnter 来规避 .NET 线程死锁的源代码

    在开发多线程的应用程序时,我们会大量用到 lock (...) {} 块.如果 lock 的对象比较多,非常容易发生死锁.死锁的发生很难预料,而且一旦发生在界面线程上,界面就不再刷新响和应用户输入:如 ...

  2. 安装openblas库

    http://www.openblas.net/ Linux:下载源码直接make即可

  3. 【转】tar命令详解

    原文:http://www.cnblogs.com/qq78292959/archive/2011/07/06/2099427.html tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压 ...

  4. nohup命令(Linux终端启动后台运行程序)

    1. nohup指令基本概念: nohup: 不挂断的运行,并没有后台运行功能,用nohup运行命令可以使命令永久执行下去,和用户终端没有关系,断开SSH不影响运行,&是后台运行. nohup ...

  5. VM 下增加磁盘空间

    随着Linux虚拟机的不断使用,在VMware中经常遇到 预先装好的 linux 虚拟机的硬盘空间过小 的问题,造成很多软件不能安装, 而重新装一个,又挺麻烦.于是,上网搜了下关于 vmware 硬盘 ...

  6. 异步任务——AsyncTask的初步认识

    ProgressBar_test.class package com.example.administrator.ten_9; import android.app.Activity; import ...

  7. QTP(3)

    Test3001_Flight4a_手动启动录制购票 (VBS脚本) Window("Flight Reservation").WinObject("Date of Fl ...

  8. Maximum Xor Secondary CodeForces - 281D (单调栈)

    Bike loves looking for the second maximum element in the sequence. The second maximum element in the ...

  9. java线程基础巩固---Thread API综合实战之编写ThreadService实现暴力结束线程

    上篇中在最后抛出一个问题,具体问题可以查看此篇[http://www.cnblogs.com/webor2006/p/7995229.html],这里不再概述,其实要实现这个需求可以用咱们之前学习的守 ...

  10. springboot-拦截器redis注入空问题解决

    转自:https://blog.csdn.net/liuyang1835189/article/details/81056162 主要问题是在拦截器的配置类里面,配置的类,spring容器无法获取,所 ...