problem 2152 file system
Time limit:1000 mSec Memory limit:32768 KB
Problem Description
Each Linux file has four access rights: Readable (R), writable (W), executable (x), and no permissions (-).
You can use the Ls-l command to see the permissions for a file or directory, whichever is the first field that displays the data. The first field consists of 10 characters, as follows:
-rwxr-xr-x
The 1th bit represents the file type,-represents the file, and D indicates the directory
2-4-bit represents the permissions of the file owner, u permissions
5-7 bits represents the permissions of the members of the group to which the file belongs, G permissions
8-10-bit represents permissions for users other than the owner and members of the owning group, O permissions
The sum of 2-10-bit permissions is sometimes referred to as a permission
In the above example, this is a file (non-directory), the file owner has read, write, and execute permissions, the user of the owning group, and other users have read and Execute permissions without write permission.
Modifying permissions with numeric notation
The so-called digital notation, refers to the R, W and X respectively, 4, 2, one represents, does not grant permission is 0,
Then add the permissions, as follows
The original permission is converted to a digital numeral notation
Rwxrwxr-x (421) (421) (401) 775
Rwxr-xr-x (421) (401) (401) 755
The user's permissions to a file are determined as follows:
1. If the user is the file owner, only the "U permission" is determined, regardless of the following conditions
2. If the user is in the user list of the group that the file belongs to, then only the "G permission" is determined, regardless of the following conditions
3, if not meet the above two points, this only according to "O Permission" to determine
Now give all the users in the current system and the groups to which the user belongs. and give some information about the files.
Please help KK to resolve each user's permissions on each file, with a numeric representation.
Input
The first line is a T, which indicates that there is a T group of data
For each set of data
The first row, an n, indicates that there are N users. Next n rows, each row is formatted as
Username N1 groupname_1 groupname_2 ... groupname_n1
Indicates that the user username belongs to a N1 group, followed by each group name
Then enter an m to indicate that there are M files. The information for each file is then given in the format
filename XXX User Group
Represents a file name, permission, owning user, and owning group
0<N,M<=100, the number of group names is also less than 100, and all string lengths are less than 10.
Output
For each set of data
Outputs a n*m matrix that represents each user's permissions on each file. The numbers are separated by spaces.
Sample Input2
2
AA 2 AA BB
BB 1 bb
3
A 755 AA AA
b 644 BB bb
C 640 BB CC
1
AA 2 AA BB
1
A 755 CC AASample Output7 4 0
5 6 6
5
Title Link: http://acm.fzu.edu.cn/problem.php?pid=2152
Topic: Chinese problem, title
Topic Analysis: According to the meaning of the topic simulation can
#include <cstdio> #include <cstring> #include <map>using namespace std;int const MAX = 105;struct info{ Char user[15]; int gnum; Char g[15][15]; int ans[100];} A[max];int Main () {int n, m, T; scanf ("%d", &t); while (t--) {scanf ("%d", &n); for (int i = 0; i < n; i++) {scanf ("%s%d", A[i].user, &a[i].gnum); for (int j = 0; J < A[i].gnum; J + +) scanf ("%s", A[i].g[j]); } scanf ("%d", &m); Char s[15], u[15], g[15], code[3]; for (int i = 0; i < m; i++) {int cnt = 0; scanf ("%s%s%s", s, Code, U, g); for (int j = 0; J < N; j + +) {if (strcmp (a[j].user, u) = = 0) { A[j].ans[i] = code[0]-' 0 '; Continue } else {BOOL flag = false; for (int k =0; K < A[j].gnum; k++) {if (strcmp (A[j].g[k], g) = = 0) { Flag = true; A[j].ans[i] = code[1]-' 0 '; Break }} if (flag) continue; } A[j].ans[i] = code[2]-' 0 '; }} for (int i = 0, i < n; i++) {for (int j = 0; J < M-1; j + +) print F ("%d", a[i].ans[j]); printf ("%d\n", a[i].ans[m-1]); } }}
Fzu 2152 File System (small analog)