FZU2152 文件系统 小模拟
来源:互联网 发布:最热网络词条 编辑:程序博客网 时间:2024/05/17 06:10
Description
每个Linux文件具有四种访问权限:可读(r)、可写(w)、可执行(x)和无权限(-)。
利用ls -l命令可以看到某个文件或目录的权限,它以显示数据的第一个字段为准。第一个字段由10个字符组成,如下:
-rwxr-xr-x
第1位表示文件类型,-表示文件,d表示目录
2-4位表示文件所有者的权限,u权限
5-7位表示文件所属组的成员的权限,g权限
8-10位表示所有者和所属组的成员之外的用户的权限,o权限
2-10位的权限总和有时称为a权限
以上例子中,表示这是一个文件(非目录),文件所有者具有读、写和执行的权限,所属组的用户和其他用户具有读和执行的权限而没有写的权限。
用数字表示法修改权限
所谓数字表示法,是指将r、w和x分别用4、2、1来代表,没有授予权限的则为0,
然后把权限相加,如下
原始权限 转换为数字 数字表示法
rwxrwxr-x (421)(421)(401) 775
rwxr-xr-x (421)(401)(401) 755
判断用户对一个文件的权限是这样的:
1、如果用户是文件所有者,则只按”u权限”判定,不考虑以下条件
2、如果用户在文件所属组的用户列表里,则只按”g权限”判定,不考虑以下条件
3、如果不满足以上两点,这只按”o权限”判定
现在给出当前系统中的所有用户以及用户所属的组。并且给出一些文件的信息。
请帮kk解决每个用户对每个文件的权限,用数字表示显示。
Input
第一行一个T,表示有T组数据
对于每组数据
第一行一个n表示有n个用户。接着n行,每行格式为
username n1 groupname_1 groupname_2 … groupname_n1
表示用户username属于n1个组,接着为每个组名
接着输入一个m,表示有m个文件。接着给出每个文件的信息,格式为
filename xxx user group
表示文件名、权限、所属用户和所属组
0
Output
对于每组数据
输出一个n*m的矩阵,表示每个用户对每个文件的权限。数字间用空格隔开。
Sample Input
2
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 AA
Sample Output
7 4 0
5 6 6
5
解题思路
关于unix中文件权限的小模拟。细心即可,1A
代码
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 15;struct file { char nameoffile[maxn]; char owner[maxn]; char groupoffile[maxn]; int powerofowner,powerofgroup,powerofothers;};struct user { char nameofuser[maxn]; int cntofgroup; char groupofuser[110][maxn];};file f[110];user u[110];void init(void){ for(int i = 0 ; i < 110 ; i ++) { memset(f[i].nameoffile,0,sizeof(f[i].nameoffile)); memset(f[i].owner,0,sizeof(f[i].owner)); memset(f[i].groupoffile,0,sizeof(f[i].groupoffile)); f[i].powerofowner = f[i].powerofgroup = f[i].powerofothers = -1; memset(u[i].nameofuser,0,sizeof(u[i].nameofuser)); memset(u[i].groupofuser,0,sizeof(u[i].groupofuser)); u[i].cntofgroup = 0; }}bool isowner(user a,file b){ if(strcmp(a.nameofuser,b.owner) == 0) return true; else return false;}bool isgroup(user a,file b){ for(int i = 0 ; i < a.cntofgroup ; i ++) { if(strcmp(a.groupofuser[i],b.groupoffile) == 0) return true; } return false;}int main(){ //freopen("in.txt","r",stdin); int t; scanf("%d",&t); while(t--) { init(); int n,m;//n个人,m个文件 scanf("%d",&n); for(int i = 0 ; i < n ; i ++) { scanf("%s",u[i].nameofuser); int cnt; scanf("%d",&cnt); u[i].cntofgroup = cnt; for(int j = 0 ; j < cnt ; j ++) { scanf("%s",u[i].groupofuser[j]); } } scanf("%d",&m); for(int i = 0 ; i < m ; i ++) { scanf("%s",f[i].nameoffile); char power[5]; scanf("%s",power); f[i].powerofowner = power[0]-'0'; f[i].powerofgroup = power[1]-'0'; f[i].powerofothers = power[2]-'0'; scanf("%s%s",f[i].owner,f[i].groupoffile); } //处理+输出 bool first = true; for(int i = 0 ; i < n ; i ++) { for(int j = 0 ; j < m ; j ++) { //判断第i人对第j个文件的权限 int mod; if(isowner(u[i],f[j])) {//所有者 mod = f[j].powerofowner; }else if(isgroup(u[i],f[j])) {//同组 mod = f[j].powerofgroup; }else {//others mod = f[j].powerofothers; } if(first) { printf("%d",mod); first = false; }else printf(" %d",mod); } printf("\n"); first = true; } } return 0;}
- FZU2152 文件系统 小模拟
- FZU 2152 文件系统 (小模拟)
- 模拟文件系统
- 模拟的多级文件系统
- 模拟操作系统文件系统
- 模拟文件系统课程设计
- linux文件系统模拟
- 【java】文件系统管理模拟
- python编写模拟文件系统
- NTFS 文件系统小秘密
- ext2文件系统小总结
- UNIX 类文件系统模拟实现
- linux下简单模拟文件系统
- 【linux小菜鸟】根文件系统
- 模拟小时钟源代码
- 模拟小练
- hdu4515 小模拟
- 小模拟认知
- 杭电 HDU 1035 Robot Motion
- org.apache.jasper.JasperException: /pages/column.jsp (line: 8, column: 1) File "pathTags.jsp" not f
- 职场感悟闲谈
- 深圳程序员面试经验
- ZOJ3785What day is that day? 规律
- FZU2152 文件系统 小模拟
- 一切成功源于积累——20150321 22点35至26点的 阶段涨 新美2.20%
- vim cheat sheet
- vim note (1)
- vim note (2)
- vim note(3)
- vim 学习总结
- 130 个你需要了解的 vim 命令
- Recover Binary Search Tree