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 ...
随机推荐
- 【Leetcode】Partition List (Swap)
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- 建立ORACLE10G DATA GUARD--->Physical Standby
下面是我自己建Physical Standby,按照下面的步骤一步我一步,当然,打造成功,以下步骤可以作为建筑物Data Guard结构操作手册. HA和DG差额:HA:可以做IP切换自己主动 DG ...
- C++生产和使用的临时对象
所谓暂时对象就是一种无名对象. 它的出现假设不在程序猿的预期之下(比如不论什么pass by value操作都会引发copy操作,于是形成一个暂时对象),往往照成效率上的负担. 但有时候能够制造 ...
- android 如何将电话簿SDN数字和其他普通的数字混合在一起?
最初的设计将默认SDN单独分出来,副标题"SDN". 下面的变化可以通过例如实现SDN并安排普通相同数量在一起,按字母顺序排列. DefaultContactListAdapter ...
- 使用Canvas和Paint自己绘制折线图
主要用于Canvas一个特别简单的小demo. 能够手动点击看每一个月份的数据.很easy.就是用paint在canvas上画出来的. 主要内容就是计算左边价格的位置,以下日期的位置,三根虚线的位置, ...
- ssh连接失败,排错经验(转)
一.场景描述 ssh连接服务器,发现连接失败,但是对应服务器的ip能够ping通. 场景: [root@yl-web ~]# ssh root@10.1.101.35 ssh_exchange_ide ...
- 【剑指offer】最小的k的数量
转载请注明出处:http://blog.csdn.net/ns_code/article/details/26966159 题目描写叙述: 输入n个整数,找出当中最小的K个数.比如输入4,5,1,6, ...
- REST WebService
REST WebService 前置技能 ① 使用maven来管理java项目 这个技能必须点一级,以便快速配置项目. 本文实际上是我学习Spring的过程中搬的官网上的demo,使用maven配置项 ...
- 标准SVD和改进的SVD
参考链接:http://www.cnblogs.com/yangxiao99/p/4752890.html 参考链接:http://www.cnblogs.com/yangxiao99/p/47529 ...
- Ruby 一些经常使用的细节
1.try 永远不会抛出异常 在 没有的时候 返回 nil province_id = Province.find_by_name(prov).try(:id) 2.find(:first, :con ...