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 ...
随机推荐
- Ubuntu 14.04 Android 使用Maven一个 用例project
在说明书前面描述SDK通过使用Ant发展. 本文试图在此基础上使用Maven发展. 在这里,我们需要使用maven-android-plugin. 在本文中,参考官方文件: https://code. ...
- js Array 阵列扩展方法
//又来了 Array.prototype.unique = function() { this.sort(); var re=[this[0]]; for(var i = 1; i < thi ...
- windows rt 扫描二维码
项目中使用的是ZXing.net,应用商店程序.使用到的dll是ZXing.winmd. 大致思路为,使用MediaCapture捕获图片.获取到CapturePhotoToStreamAsync流, ...
- Sonar Qube QA
配置:1.配置环境变量 SONAR_RUNNER_HOME2.配置path :增加%SONAR_RUNNER_HOME%\bin3.在自己的本地项目的根目录下创建 sonar-project.pro ...
- Linux
介绍了相关的文件夹
学习Linux,先了解Linux标准的文件夹结构是非常重要的,学习的一个很好的铺垫之后的行动.去罗列大而全的所有文件夹. 本文主要说明.笔者本人接触,须要了解的一些文件文件夹,当然本文也会不断的更新或 ...
- Java NIO系列教程(三) Buffer(转)
Java NIO中的Buffer用于和NIO通道进行交互.如你所知,数据是从通道读入缓冲区,从缓冲区写入到通道中的. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO ...
- 《Javascript权威指南》学习笔记之十八:BOM新成就(1)--client存储数据(Web SQL DataBase实现)
使用本地存储和会话存储能够实现简单的对象持久化,能够对简单的键值对或对象进行存储.可是,对于比較复杂的关系数据进行处理时,就要用Web SQL Database.浏览器对Web SQL Databas ...
- 模仿QQ截图片
原文:模仿QQ截图片 两个picturebox,一个放图片 完整代码如下 using System; using System.Collections.Generic; using System.Co ...
- Codeforces 374D Inna and Sequence 二分法+树状数组
主题链接:点击打开链接 特定n一个操作,m长序列a 下列n的数量 if(co>=0)向字符串加入一个co (開始是空字符串) else 删除字符串中有a的下标的字符 直接在序列上搞.简单模拟 # ...
- Python的print中国输出对齐问题
问题叙述性说明: 在使用Python内置函数print当输出英语,应用格输出类型可以对齐很好: s1 = 'I am a long sentence.' s2 = 'I\'m short.' prin ...