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. CPP-基础:有关调用约定

    在C语言中,假设咱们有这样的一个函数:int function(int a,int b) 调历时只有用result = function(1,2)的方法就能利用这个函数.然而,当高档语言被编译成计算机 ...

  2. 使用struts2实现文件上传与下载功能

    这个问题做了两天,在网上找了很多例子,但是还有一些功能没有实现,暂时先把代码贴出来,以后在做这方面的功能时在修改 文件上传: 一开始我在网上找到基于servlet+jsp环境写的文件上传,但是在将页面 ...

  3. 关于lua 5.3 服务端热更新流程

    脚本的热更新的流程都大同小异, 第一步先保存旧代码的块的数据, 第二部加载新的代码块,第三步将旧代码块的局部和全局数据拷贝到新代码块的对应的 变量中. 在服务器热更新中,主要考虑热更的内容是什么, 一 ...

  4. css3中的nth-child和nth-of-type的区别

    实例: 首先创建一个HTML结构 <div class="post"> <p>我是文章的第一段落</p> <p>我是文章的第二段落& ...

  5. 【转】嵌入式操作系统VxWorks中TFFS文件系统的构建

    时间:2005-02-20 来源:21IC中国电子网 作者:771所加固机工程部 蔡本华 高文炜 关键字:VxWorks   TFFS   嵌入式操作系统   文件系统       摘要:目前的嵌入式 ...

  6. 【主席树】bzoj1112: [POI2008]砖块Klo

    数据结构划一下水 Description N柱砖,希望有连续K柱的高度是一样的. 你可以选择以下两个动作 1:从某柱砖的顶端拿一块砖出来,丢掉不要了. 2:从仓库中拿出一块砖,放到另一柱.仓库无限大. ...

  7. 【mysql】mysql has gone away

    原文 http://www.jb51.net/article/23781.htm MySQL server has gone away 问题的解决方法 投稿:mdxy-dxy 字体:[增加 减小] 类 ...

  8. biological clock--class

    '''this application aimed to cauculate people's biological block about emotional(28), energy(23),int ...

  9. MyBatis的增删改查操作

    搭建好mybatis之后 进行对数据库的操作 添加语句 在映射文件中添加语句 insert into student(name,age,score) values(#{name},#{age},#{s ...

  10. JAVA基础篇—接口实现动态创建对象

    Scanner在控制台输入内容 package com.Fruit; public interface Fruit {//提供接口 } package com.Fruit; public class ...