HDU——2723Electronic Document Security(STL map嵌套set做法)
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
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.
any whitespace.
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.
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
#
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做法)的更多相关文章
- HDU 4585 Shaolin(STL map)
Shaolin Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit cid= ...
- HDU 4941 Magical Forest --STL Map应用
题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...
- HDU 1263 水果 (STL map)
水果 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 4585 Shaolin (STL map)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- 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?proble ...
- stl::map之const函数访问
如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...
- hdu4941 Magical Forest (stl map)
2014多校7最水的题 Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit ...
- [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 ...
- STL MAP及字典树在关键字统计中的性能分析
转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...
随机推荐
- SQLServer锁原理和锁的类型
1.锁的用途 为了避免同时争夺数据库资源,将数据库加锁,只有拿到钥匙的用户才能使用: 2.锁的粒度 行锁(Row)--->页锁(Page)--->区锁(Partition 8个页)---- ...
- HTTP无状态协议和session原理(access_token原理)
无状态协议是指协议对务处理没有记忆能力.缺少状态意味着如果后续处理需要前面的信息,则它必须重传,这样可能导致每次连接传送的数据量增大.另一方面,在服务器不需要先前信息时它的应答就较快. Http协议不 ...
- 20180901 JavaScript闭包和匿名函数自动调用
引用: 1. JavaScript闭包_by runoob 2. JS中(function(){xxx})这么写是什么意思? (一)闭包是可以访问上一层函数作用域里变量的函数,即便上一层函数已经关闭. ...
- c++ 定义一个结构体student,输入多个student的信息并以三种方式显示
#include <iostream> #include <string> using namespace std; const int slen = 30; struct s ...
- BZOJ-1833(数位DP)
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a,b; int k[20]; ll dp[2 ...
- NodeJS基础入门-Event
大多数Node.js核心API都采用惯用的异步事件驱动架构,其中某些类型的对象(触发器)会周期性地触发命名事件来调用函数对象(监听器). 例如,net.Server对象会在每次有新连接时触发事件;fs ...
- 不使用脚手架的 vue 应用
工作中的项目不止有页面繁多的模块化项目,还会只有一两个页面的类似于填写信息参与活动的活动页.这个时候,就可以回归以前的三剑客模式,在 index.html 里引用 vue.js 进行开发. 关键点: ...
- LeetCode(242)Valid Anagram
题目 Given two strings s and t, write a function to determine if t is an anagram of s. For example, s ...
- CF1029C Maximal Intersection
https://www.luogu.org/problem/show?pid=CF1029C #include<bits/stdc++.h> using namespace std ; # ...
- 关于freetype在安装中的遇到的问题
本人电脑配置的是Anconda环境+pycharm2017.2.2 comuniity,每次安装什么包就是直接pip install 的,但是这次在安装freetype的安装中却遇到了麻烦. 具体是在 ...