POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
题目链接:
PKU:http://poj.org/problem?id=3654
ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2936
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2723
Description
The Tyrell corporation uses a state-of-the-art electronic document system that controls all aspects of document creation, viewing, editing, and distribution. Document security is handled via access control lists(ACLs). An ACL defines a set of
entities that have access to the document, and for each entity defines the set of rights that it has. Entities are denoted by uppercase letters; an entity might be a single individual or an entire division. Rights are denoted by lowercase letters; examples
of rights are a for append, d for delete, e for edit, and r for read.
The ACL for a document is stored along with that document, but there is also a separate ACL log stored on a separate log server. All documents start with an empty ACL, which grants no rights to anyone. Every time the ACL for a document is changed,
a new entry is written to the log. An entry is of the form ExR, where E is a nonempty set of entities, R is a nonempty set of rights, and x is either "+", "–", or "=". Entry E+R says to grant all the rights
in R to all the entities in E, entry E–R says to remove all the rights in R from all the entities in E, and entry E=R says that all the entities in E have exactly the rights in R and
no others. An entry might be redundant in the sense that it grants an entity a right it already has and/or denies an entity a right that it doesn't have. A log is simply a list of entries separated by commas, ordered chronologically from oldest to most recent.
Entries are cumulative, with newer entries taking precedence over older entries if there is a conflict.
Periodically the Tyrell corporation will run a security check by using the logs to compute the current ACL for each document and then comparing it with the ACL actually stored with the document. A mismatch indicates a security breach. Your job is to write
a program that, given an ACL log, computes the current ACL.
Input
The input consists of one or more ACL logs, each 3–79 characters long and on a line by itself, followed by a line containing only "#" that signals the end of the input. Logs will be in the format defined above and will not contain any whitespace.
Output
For each log, output a single line containing the log number (logs are numbered sequentially starting with one), then a colon, then the current ACL in the format shown below. Note that (1) spaces do not appear in the output; (2) entities are listed in alphabetical
order; (3) the rights for an entity are listed in alphabetical order; (4) entities with no current rights are not listed (even if they appeared in a log entry), so it's possible that an ACL will be empty; and (5) if two or more consecutive entities have exactly
the same rights, those rights are only output once, after the list of entities.
Sample Input
MC-p,SC+c
YB=rde,B-dq,AYM+e
GQ+tju,GH-ju,AQ-z,Q=t,QG-t
JBL=fwa,H+wf,LD-fz,BJ-a,P=aw
#
Sample Output
1:CSc
2:AeBerMeYder
3:
4:BHJfwLPaw
Source
题意:
运算符(“‘+’, ‘-’, ''=”)前面是名字,‘+’表示把后面的权力赋给前面的人,‘-’表示从前面的人中减去后面的权力(当然没有就不减),‘=’表示把前面的人的权力先清空在把后面的权力赋给前面的人!输出的时候有同样权力的相邻两个人就名字一起输出,再一起输出权力!假设都没有权力则不输出!
代码例如以下:
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
const int maxn = 57;
int a[maxn][maxn]; int main()
{
string tt;
char str[1017];
int cas = 0;
int num[maxn];
while(scanf("%s",str)!=EOF)
{
int len = strlen(str);
if(len == 1 && str[0] == '#')
break;
tt = "";
memset(a,0,sizeof a);
for(int i = 0; i < len; i++)
{
if(str[i]==',')
tt = "";//清空
else if(str[i] == '+')
{
for(int j = i+1; str[j]!=',' && j < len; j++)
{
for(int k = 0; k < tt.size(); k++)
{
a[tt[k]-'A'][str[j]-'a']=1;
}
}
}
else if(str[i] == '-')
{
for(int j = i+1; str[j]!=',' && j < len; j++)
{
for(int k = 0; k < tt.size(); k++)
{
a[tt[k]-'A'][str[j]-'a']=0;
}
}
}
else if(str[i] == '=')
{
for(int k = 0; k < tt.size(); k++)
{
memset(a[tt[k]-'A'],0,sizeof a[0]);
for(int j = i+1; str[j]!=',' && j < len; j++)
{
a[tt[k]-'A'][str[j]-'a']=1;
}
}
}
else
tt+=str[i];
}
printf("%d:",++cas);
int l = 0;
for(int i = 0; i < 26; i++)//记录下全部有权力的人
{
int flag = 0;
for(int j = 0; j < 26; j++)
{
if(a[i][j])
flag = 1;
}
if(flag)
{
num[l++] = i;
}
} tt = "";
for(int i = 0; i < l; i++)
{
int flag = 0;
if(i != l-1)
{
for(int j = 0; j < 26; j++)
{
if(a[num[i]][j] != a[num[i+1]][j])//所含的权力不同
{
flag = 1;
}
}
}
char tem = 'A'+num[i];
tt += tem;
if(flag==1 || i==l-1)
{
cout<<tt;
tt = "";
for(int j = 0; j < 26; j++)
{
if(a[num[i]][j])
printf("%c",'a'+j);
}
}
}
printf("\n");
}
return 0;
}
POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)的更多相关文章
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...
- POJ 3652 & ZOJ 2934 & HDU 2721 Persistent Bits(数学 元)
主题链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do? probl ...
- POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...
- POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
Problem Description As we all know, machine scheduling is a very classical problem in computer scien ...
- POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)
POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang
Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nu ...
随机推荐
- C# 字符串知识整理
新知识点,只是对于本人来说而已. 系统处理文本的方式 [新知识点].NET Framework .NET Framework的定义:其包含了一个公共语言运行时(Common Language Runt ...
- JS它DOM
DOM:document object model.文档对象模型.它主要由许多节点.而基于JS对象的一切视角,DOM核心是节点对象和操作方法的属性.从下面三方面来介绍DOM. 一.节点查找与操作 这部 ...
- Redis源代码分析(二十)--- ae事件驱动
事件驱动的术语出现更频繁.听起来非常大的,今天我把Redis内部驱动器模型来研究它,奖励的感觉啊.一个ae.c主程序,加4文件的事件类型,让你彻底弄清楚,Redis是怎样处理这些事件的. 在Redis ...
- SAP ABAP规划 使用LOOP READ TABLE该方法取代双LOOP内部表的方法
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWlueXVlemhhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- kendo ui 单击取消编辑数据grid减少的原因和治疗方法的数据
kendo ui单击取消编辑数据buttongrid数据缩减.原因grid编辑数据追打datasorce于data寻找阵列数据的存在.假定有不会加入,加入缺席. 首先一个样本: html代码: < ...
- java json字符串转List、Map等对象
List<Map<String, Object>> map = g.fromJson(jsonStr, new TypeToken<List<Map<Stri ...
- WebService到底是什么? [转]
一.序言 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是Web ...
- I2C驱动程序框架probe道路
基于Linux的I2C驱动器.采纳probe道路.根据这个框架,如下面就可以写任何支持I2C总线设备Linux驱动器. I2C设备连接到cpu具体i2c接口.被安装在cpu的i2c适配器.i2c设备和 ...
- hdu Text Reverse
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 单词翻转! 代码: #include <stdio.h> #include < ...
- EntityFramework:状态变化与方法的关系
一.约定 OnModelCreated 有一些限制需要注意,例如: 1.表名不支持使用标签进行标注 2.最小长度在 OnModelCreated 中不支持 3.正则表达式在 O ...