Electronic Document Security

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 172    Accepted Submission(s): 94

Problem 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

这题是我写过最长的代码题。也是我个大菜鸟写过最复杂的..对于map和set又熟悉了不少。,题意:每一行输入多个names(集合) x rights(集合),name和rights是字符串,x是操作符+、-、=。

举个例子,GOQ=ab,则产生G、O、G三个人(并先清空当前所有权限),每一个人都赋给a与b的权限,题目所给的写法可以视为对一个name集合的每一个字符进行操作,再举个例子,GOQ+ab,则将G、O、Q三个人均加上a与b的权限(若已有则不变)再举个栗子吧GOQ-ab,则将G、O、Q三个人权限中均减掉a与b(若原来就没有就不用减)

题目输出要求:对于具有相同权限的人按字典序排序再合并输出,若某人无任何权限,则不输出。因为按字典序,则用map,又由于每一个人的权限重复删除、增加问题,则用set。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<set>
using namespace std;
int main(void)
{
string t,s,name,miaoshu;
char na;
int i,j,k,mid,coma,q,len,p=0;
while (getline(cin,t)&&t!="#")
{
p++;//输入计数器
set<char> right;
map<char,set<char> >list;
map<char,set<char> >::iterator mit,tmit;
set<char>::iterator sit;
map<char,set<char> >::reverse_iterator jmit,kmit;
k=0;
while (t.find(",",k)!=string::npos)//由于结尾无逗号,只能先处理前n-1个短句
{
coma=t.find(",",k);
for (i=k; i<coma; i++)
{
if(t[i]=='-')
{
for (j=k; j<i; j++)
{
for(q=i+1; q<coma; q++)
{
if(list[t[j]].count(t[q])!=0)
list[t[j]].erase(t[q]);
}
}
break;
}
else if(t[i]=='+')
{
for (j=k; j<i; j++)
{
for(q=i+1; q<coma; q++)
{
if(list[t[j]].count(t[q])==0)
list[t[j]].insert(t[q]);
}
}
break;
}
else if(t[i]=='=')
{
for (j=k; j<i; j++)
{
list[t[j]].clear();
for(q=i+1; q<coma; q++)
{
list[t[j]].insert(t[q]);
}
}
break;
}
}
k=coma+1;
}
//开始处理最后一个句子
len=t.size();
for (i=k; i<len; i++)
{
if(t[i]=='-')
{
for (j=k; j<i; j++)
{
for(q=i+1; q<len; q++)
{
if(list[t[j]].count(t[q])!=0)
list[t[j]].erase(t[q]);
}
}
break;
}
else if(t[i]=='+')
{
for (j=k; j<i; j++)
{
for(q=i+1; q<len; q++)
{
if(list[t[j]].count(t[q])==0)
list[t[j]].insert(t[q]);
}
}
break;
}
else if(t[i]=='=')
{
for (j=k; j<i; j++)
{
list[t[j]].clear();
for(q=i+1; q<len; q++)
{
list[t[j]].insert(t[q]);
}
}
break;
}
}
//处理完毕
for (mit=list.begin(); mit!=list.end(); mit++)//找出没有权限的人,抹掉他
{
if((mit->second).empty())
list.erase(mit++);
}
printf("%d:",p);
for (mit=list.begin(); mit!=list.end(); mit++)
{
tmit=mit;
tmit++;
if((tmit->second)!=(mit->second)&&!(mit->second).empty())//若第n个与第n-1个权限不相同且权限不为空,则说明不用合并
{
cout<<mit->first;
for(sit=(mit->second).begin(); sit!=(mit->second).end(); sit++)
cout<<*sit;
}
else if(!(mit->second).empty())//若权限相同且不为空则只要输出名字即可
cout<<mit->first;
}
printf("\n");
}
return 0;
}

HDU——2723Electronic Document Security(STL map嵌套set做法)的更多相关文章

  1. HDU 4585 Shaolin(STL map)

    Shaolin Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit cid= ...

  2. HDU 4941 Magical Forest --STL Map应用

    题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...

  3. HDU 1263 水果 (STL map)

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  4. HDU 4585 Shaolin (STL map)

    Shaolin Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  5. POJ 3654 &amp; ZOJ 2936 &amp; HDU 2723 Electronic Document Security(模拟)

    题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  6. stl::map之const函数访问

    如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...

  7. hdu4941 Magical Forest (stl map)

    2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit ...

  8. [CareerCup] 13.2 Compare Hash Table and STL Map 比较哈希表和Map

    13.2 Compare and contrast a hash table and an STL map. How is a hash table implemented? If the numbe ...

  9. STL MAP及字典树在关键字统计中的性能分析

    转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...

随机推荐

  1. 手机屏幕材质详解(TFT,TPS,OLED,AMOLED等)

    手机屏幕概括起来就是两种,一个是LCD,一个是OLED屏幕,这两个是屏幕显示技术的两大基础. 一 . LCD:Liquid Crystal Display,这是一种介于固态和液态之间的物质,称为液晶技 ...

  2. jquery的正则表达式

    正则表达式 位置: ^      开头 $      结尾 次数: *      0或多个 +      1或多个 ?      0或1个 {n}     就是n个 {n,}   至少n个 {n,m} ...

  3. WinForm中Timer倒计时

    添加一个Timer控件: 在初始化代码中 public Form1() { InitializeComponent(); button_Read.Enabled = false; button_Sta ...

  4. Manifest文件

    Manifest文件是简单的文本文件,它告知浏览器缓存的内容(或不缓存的内容) Manifest文件可以分为三个部分: 1.CAHCEMANIFEST-在此标题下列出的文件将在首次下载后进行缓存. C ...

  5. iOS开发之蓝牙业务封装

    因为公司做智能家居开发,有很多蓝牙的智能硬件.因此项目中经常需要和蓝牙打交道.为此为了提高开发效率,就把蓝牙的公共业务进行了封装. 本文将对封装的思路做一个简单的阐述. 首先我们需要一个头文件.在这个 ...

  6. linux系统下的用户文件句柄数限制

    linux系统下的用户文件句柄数限制 文章来源:企鹅号 为什么要修改用户打开的文件数 系统默认单个进程可以打开1024个文件,对于一些应用如tomcat.oracle等,运行时经常open成千上万个文 ...

  7. Diff Two Arrays-freecodecamp算法题目

    Diff Two Arrays(比较两个数组) 1.要求 比较两个数组,然后返回一个新数组 该数组的元素为两个给定数组中所有独有的数组元素.换言之,返回两个数组的差异. 2.思路 定义一个新数组变量, ...

  8. spring boot yaml 自定义配置 映射到 java POJO

    只需要一个注解就ok: @ConfigurationProperties("user.other") “user.other” 这个值匹配的是user下的other对象 yaml ...

  9. python文件打包为exe可执行文件的方法

    我自己常用Pyinstaller库打包 第一步: 安装pyinstaller库   pip install pyinstaller 第二步: 在py文件所在目录输入 mydemo.py是自己写的py文 ...

  10. 这五本Python急速入门必读的书,送给正在学习Python的你!

    书籍是人类进步的阶梯,这句话从古至今都是适用的.为什么会这么说呢?书籍,它记录了人们实践的经验,这些经验有助于我们快速的学习,对于编程学习来说也不例外,今天就给大家带来了以下的书籍干货,希望能够帮助到 ...