EOJ:Electronic Document Security

Electronic Document Security

Time Limit: 1000MS Memory Limit: 65536K
Total Submits: 25 Accepted: 19

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 appendd for deletee 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 ER 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
原题:http://202.120.106.94/onlinejudge/problemshow.php?pro_id=156
————————————————————————————————————————————————————————————————————
没啥好说的,就是模拟,精妙之处在于用二进制表示当前文件的属性,+-=则用位运算来处理。
代码
1 #include<stdio.h>
2 #include<memory.h>
3 #include<string.h>
4  #define maxn 100
5  int x,y,z,i,j,right,t;
6  int rights[27];
7  char str[maxn];
8  bool flag[27];
9 int trans(int l,int r)
10 {
11 int i,temp;
12 temp=0;
13 for (i=l;i<=r;i++)
14 temp+=1<<(str[i]-65);
15 return temp;
16 }
17 void retrans(char str[],int x)
18 {
19 int top,i;
20 char temp[100];
21 top=0;
22 for (i=0;i<26;i++)
23 {
24 if (x%2==1) temp[top++]=i+97;
25 x=x/2;
26 }
27 temp[top]='\0';
28 strcpy(str,temp);
29 }
30 void update(int x,int y,char c)
31 {
32 int temp;
33 if (c=='+')
34 {
35 rights[str[x]-65]=rights[str[x]-65]|y;
36 return;
37 }
38 if (c=='=')
39 {
40 rights[str[x]-65]=y;
41 return;
42 }
43 temp=((~y)&((1<<26)-1));
44 rights[str[x]-65]=temp&rights[str[x]-65];
45 }
46 int main()
47 {
48 t=0;
49 while (1)
50 {
51 t++;
52 gets(str);
53 if (strcmp(str,"#")==0) break;
54 z=0;
55 memset(flag,0,sizeof(flag));
56 memset(rights,0,sizeof(rights));
57 while (1)
58 {
59 y=z;
60 if (z>=strlen(str)) break;
61 while (y<strlen(str)&&str[y]!=',')
62 {
63 if (str[y]=='-'||str[y]=='='||str[y]=='+')
64 x=y;
65 y++;
66 }
67 right=trans(x+1,y-1);
68 for (i=z;i<x;i++)
69 update(i,right,str[x]);
70 z=y+1;
71 }
72 printf("%d:",t);
73 for (i=0;i<26;i++)
74 {
75 if (rights[i]>0&&flag[i]==false)
76 {
77 for (j=i;j<26;j++)
78 if (rights[j]==rights[i])
79 {
80 printf("%c",j+65);
81 flag[j]=true;
82 }
83 else if(rights[j]!=0) break;
84 retrans(str,rights[i]);
85 printf("%s",str);
86 }
87 }
88 printf("\n");
89 }
90 return 0;
91 }

 


posted on 2011-02-04 20:30  风也轻云也淡  阅读(123)  评论(0编辑  收藏  举报