procedure pcreate; //创建文件 label a,b; begin write('User name?'); readln(x); for i:=1 to 5 do if x=mfd[i]^.username then goto b; //找到匹配的跳b writeln(x,'not been logined !'); goto a; //找不到匹配的跳a b:write('New file name?'); readln(x); p2:=mfd[i]^.link; if p2^. filename=x then {检查是否与用户的第一个文件重名} begin writeln('File has existed!'); goto b; end; while p2^.next<>NIL {检查是否与用另外的文件重名} do begin p2:=p2^.next; if p2^.filename=x then begin writeln('file has existed!'); goto b; end; end; new(q2); //创建新的文件节点q2 q2^.next:=NIL; q2^.filename:=' '; p2^.next:=q2; p2^.filename:=x; repeat write('Protection code?'); readln(y1);val(y1,y,code); until code=0; p2^.pcode:=y; p2^.length:=0; writeln('Create finished !'); a:end; 设置数据域pcode的目的是什么?请说明如何发挥它的作用?
时间: 2024-01-05 10:04:02 浏览: 136
数据域`pcode`的目的是为了设置文件的保护码,即文件访问权限。通过设置不同的保护码,可以限制不同用户对文件的访问权限,保护文件的安全性。
在程序中,当创建新文件时,会要求用户设置保护码,并将其存储在文件节点的`pcode`数据域中。在后续的文件操作中,如果用户想要访问该文件,程序会要求用户输入保护码进行验证,只有输入正确的保护码才能够访问该文件。这样就可以达到控制用户对文件的访问权限的目的。
相关问题
var booth: array[0..400] of integer; t: array[0..400, 0..400] of integer; dp: array[0..400] of integer; n, i, j, flag, ans: integer; begin readln(n); for i := 0 to n - 1 do readln(booth[i]); for i := 0 to n - 1 do for j := 0 to n - 1 do readln(t[i, j]); for i := 0 to n - 1 do if t[0, i] <= booth[i] then dp[i] := 1; flag := 1; while flag <> 0 do begin flag := 0; for i := 0 to n - 1 do for j := 0 to n - 1 do if (t[i, j] <= (booth[j] - booth[i])) and (dp[j] <= dp[i]) and (i <> j) then begin dp[j] := dp[i] + 1; flag := 1; end; end; ans := 0; for i := 0 to n - 1 do if ans < dp[i] then ans := dp[i]; writeln(ans); end.转换为c语言代码
```c
#include <stdio.h>
int booth[401], t[401][401], dp[401];
int main() {
int n, i, j, flag, ans;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &booth[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &t[i][j]);
}
}
for (i = 0; i < n; i++) {
if (t[0][i] <= booth[i]) {
dp[i] = 1;
}
}
flag = 1;
while (flag != 0) {
flag = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (t[i][j] <= (booth[j] - booth[i]) && dp[j] <= dp[i] && i != j) {
dp[j] = dp[i] + 1;
flag = 1;
}
}
}
}
ans = 0;
for (i = 0; i < n; i++) {
if (ans < dp[i]) {
ans = dp[i];
}
}
printf("%d\n", ans);
return 0;
}
```
把这份代码转换成c++代码var n,i,j,p,x,min,tot,t,len:longint; 2 out_,in_,a,heap:array[0..30005] of longint; 3 son,nxt:array[0..1000005] of longint; 4 lnk:array[0..30005] of longint; 5 procedure print_no; 6 begin 7 writeln('no solution'); 8 close(input); close(output); 9 halt; 10 end; 11 procedure put(id:longint); 12 var i:longint; 13 begin 14 inc(len); heap[len]:=id; i:=len; 15 while (i>1) do 16 begin 17 if (heap[i>>1]>heap[i]) then 18 begin 19 heap[0]:=heap[i]; heap[i]:=heap[i>>1]; heap[i>>1]:=heap[0]; 20 i:=i>>1; 21 end 22 else break; 23 end; 24 end; 25 function get:longint; 26 var fa,son:longint; 27 begin 28 get:=heap[1]; heap[1]:=heap[len]; dec(len); fa:=1; 29 while (fa<<1<=len) do 30 begin 31 if (fa<<1+1>len) or (heap[fa<<1]<heap[fa<<1+1]) then son:=fa*2 32 else son:=fa*2+1; 33 if heap[fa]>heap[son] then 34 begin 35 heap[0]:=heap[fa]; heap[fa]:=heap[son]; heap[son]:=heap[0]; 36 fa:=son; 37 end 38 else break; 39 end; 40 end; 41 procedure add(x,y:longint); 42 begin 43 inc(tot); son[tot]:=y; nxt[tot]:=lnk[x]; lnk[x]:=tot; 44 end; 45 begin 46 readln(n); 47 for i:=1 to n do 48 begin 49 read(out_[i]); 50 for j:=1 to out_[i] do 51 begin 52 read(x); inc(in_[x]); add(i,x); 53 end; 54 end; 55 min:=maxlongint; 56 for i:=1 to n do 57 if (in_[i]=0) then begin min:=0; put(i); end; 58 if min<>0 then print_no; 59 repeat 60 p:=get; inc(t); a[t]:=p; j:=lnk[p]; 61 in_[p]:=-1; 62 while j<>0 do 63 begin 64 dec(in_[son[j]]); 65 if in_[son[j]]=0 then put(son[j]); 66 j:=nxt[j]; 67 end; 68 until len=0; 69 writeln(t); 70 for i:=1 to t do write(a[i],' '); 71 end.
以下是将给定的代码转换成 C++ 代码的结果:
```c++
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int MAXN = 30005;
const int MAXM = 1000005;
int n, len, tot, t, min, out_[MAXN], in_[MAXN], a[MAXN], heap[MAXN];
int son[MAXM], nxt[MAXM], lnk[MAXN];
void print_no() {
cout << "no solution" << endl;
exit(0);
}
void put(int id) {
++len;
heap[len] = id;
int i = len;
while (i > 1) {
if (heap[i >> 1] > heap[i]) {
swap(heap[i], heap[i >> 1]);
i >>= 1;
} else {
break;
}
}
}
int get() {
int fa = 1, son;
int res = heap[1];
heap[1] = heap[len];
--len;
while ((fa << 1) <= len) {
if ((fa << 1) + 1 > len || heap[fa << 1] < heap[(fa << 1) + 1]) {
son = fa << 1;
} else {
son = (fa << 1) + 1;
}
if (heap[fa] > heap[son]) {
swap(heap[fa], heap[son]);
fa = son;
} else {
break;
}
}
return res;
}
void add(int x, int y) {
++tot;
son[tot] = y;
nxt[tot] = lnk[x];
lnk[x] = tot;
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> out_[i];
for (int j = 1; j <= out_[i]; ++j) {
int x;
cin >> x;
++in_[x];
add(i, x);
}
}
min = INT_MAX;
for (int i = 1; i <= n; ++i) {
if (in_[i] == 0) {
min = 0;
put(i);
}
}
if (min != 0) {
print_no();
}
while (len > 0) {
int p = get();
a[++t] = p;
int j = lnk[p];
in_[p] = -1;
while (j != 0) {
--in_[son[j]];
if (in_[son[j]] == 0) {
put(son[j]);
}
j = nxt[j];
}
}
cout << t << endl;
for (int i = 1; i <= t; ++i) {
cout << a[i] << " ";
}
cout << endl;
return 0;
}
```
阅读全文