HDU——2723Electronic Document Security(STL map嵌套set做法)
来源:互联网 发布:淘宝上的睡衣模特 编辑:程序博客网 时间:2024/05/16 15:33
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.
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+cYB=rde,B-dq,AYM+eGQ+tju,GH-ju,AQ-z,Q=t,QG-tJBL=fwa,H+wf,LD-fz,BJ-a,P=aw#
Sample Output
1:CSc2:AeBerMeYder3: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;}
0 0
- HDU——2723Electronic Document Security(STL map嵌套set做法)
- hdu 2723 Electronic Document Security
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
- HDU2723 Electronic Document Security【字符串】【水题】
- The SetStack Computer UVA12096 STL set map LRJ做法
- hdu 2094 产生冠军(STL map || 拓扑 || STL set)
- hdu 1029 map做法
- STL容器(map)————HDU例题
- (STL,map嵌套)水果
- stl之关联容器——set,map,hashtable
- STL学习——set/map/multiset/mulitmap篇
- STL关联式容器——set和map
- 初识STL——set,multiset,map,multimap
- STL — Map和Set的简易实现
- HDU 2072 (STL set)
- 从零开始_学_数据结构(五)——STL(map、set、list、vector)
- STL学习——STL中的关联式容器总结(RB-tree、set、map、hashtable、hash_set、hash_map)
- hdu4022 Bombing stl(map+set)
- C++: char* 与 string类型转换
- JavaScript arguments 对象
- 【千里之行,始于足下】游戏服务端开发--前言
- 树莓派FM广播点歌系统
- 《python基础教程》第一章 基础知识
- HDU——2723Electronic Document Security(STL map嵌套set做法)
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemA:Accurately Say "CocaCola"!
- Spring Boot Junit单元测试
- for循环绑定监听事件索引值总是最后一个
- Toradex 发布基于ARM系统模块的Windows 10 IoT Core 技术预览版
- poj 2411 骨牌覆盖问题 状压dp
- java基础(函数)
- ubuntu卡在stopping restore sound card state
- Linux精讲——chmod命令