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中 ...
随机推荐
- vue中的修饰符
Vue2.0学习笔记:Vue事件修饰符的使用 事件处理 如果需要在内联语句处理器中访问原生DOM事件.可以使用特殊变量$event,把它传入到methods中的方法中. 在Vue中,事件修饰符处理 ...
- 得到本地应用程序的EXE的路径
实现效果: 知识运用: Application类的ExecutablePath属性 //获取启动了应用程序的可执行文件的路径和可执行文件的名称 public static string Exec ...
- PAT (Basic Level) Practise (中文)-1019. 数字黑洞 (20)
http://www.patest.cn/contests/pat-b-practise/1019 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第 ...
- iOS跳转到各种系统设置界面
定位服务 定位服务有很多APP都有,如果用户关闭了定位,那么,我们在APP里面可以提示用户打开定位服务.点击到设置界面设置,直接跳到定位服务设置界面.代码如下: //定位服务设置界面 NSURL *u ...
- C语言输出多位小数
#include<stdio.h>#include<stdlib.h>int main(){int i=0;int m=19;int n=3;int s=0;s=m/n;pri ...
- 在Keras中导入测试数据的方法
https://blog.csdn.net/ethantequila/article/details/80322425?utm_source=blogxgwz2
- 【上下界网络流】bzoj2502: 清理雪道
模型:无源汇有上下界可行流 LJN:模板题吧 Description 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的 ...
- CentOS7练习
为编译安装的httpd服务,实现service unit文件破解centos7 口令修改默认的启动内核为新编译内核启动时临时禁用SELinux启动时进入emergency模式卸载编译安装的新内核
- Python pip 使用国内镜像
## 推荐源```https://mirrors.aliyun.com/pypi/simple/ 阿里镜像,速度快.稳定https://pypi.douban.com/simple/ 豆瓣镜像```# ...
- Vim如何显示和关闭行号
显示行号: set nu 去除行号: set nonu