题解:

傻逼模拟题

果断的复制了题解(还没有c++题解?)

代码:

program p2509;
type arr=array[..] of boolean;
var tot:longint;
s:array[..] of ansistring;
b:arr;
procedure init;
begin
tot:=;
while not eof do
begin
inc(tot);
readln(s[tot]);
end;
end;
procedure warn1(n:longint;c:char);
begin
writeln('Line ',n,': variable ',c,' might not have been initialized');
end;
procedure warn2(n:longint);
begin
writeln('Line ',n,': unreachable code');
end;
function judge(str:ansistring):longint;
begin
if str[]='F' then
exit()
else if str[]='E' then
exit()
else if str[]='L' then
exit()
else if str[]='N' then
exit()
else
exit();
end;
function dfs(var k:longint;var c:arr):boolean;
var d,e,c1,c2:arr;
str:ansistring;
i,j,sum:longint;
a:array[..] of longint;
b1,b2:boolean;
begin
d:=c;
while k<=tot do
begin
str:=s[k];
if judge(str)= then //赋值语句
begin
fillchar(a,sizeof(a),);
for i:= to length(str) do
if (str[i]>='A') and (str[i]<='Z') and not c[ord(str[i])-] then
inc(a[ord(str[i])-]);
for i:= to do
if a[i]> then
warn1(k,chr(i+));
c[ord(str[])-]:=true;
end
else if judge(str)= then //return语句
begin
fillchar(a,sizeof(a),);
for i:= to length(str) do
if (str[i]>='A') and (str[i]<='Z') and not c[ord(str[i])-] then
inc(a[ord(str[i])-]);
for i:= to do
if a[i]> then
warn1(k,chr(i+));
sum:=;
j:=k;
inc(k);
while k<=tot do
begin
str:=s[k];
if judge(str)= then inc(sum);
if sum= then
if (str[]='L') or (str[]='N') then
begin
for i:=j+ to k- do
if judge(s[i])<= then warn2(i);
c:=d;
exit(true);
end;
if str[]='N' then dec(sum);
inc(k);
end;
if k>tot then
for i:=j+ to tot do
if judge(s[i])<= then warn2(i);
end
else if judge(str)= then //if语句
begin
j:=;
while copy(str,j,)<>'THEN' do
inc(j);
fillchar(a,sizeof(a),);
for i:= to j- do
if (str[i]>='A') and (str[i]<='Z') and not c[ord(str[i])-] then
inc(a[ord(str[i])-]);
for i:= to do
if a[i]> then
warn1(k,chr(i+));
e:=c;
inc(k);
b1:=dfs(k,c);
c1:=c;
c:=e;
if judge(s[k])= then
begin
inc(k);
b2:=dfs(k,c);
c2:=c;
c:=e;
if b1 and not b2 then
c:=c2
else if not b1 and b2 then
c:=c1
else if not b1 and not b2 then
begin
for i:= to do
if c1[i] and c2[i] then c[i]:=true;
end;
b1:=b1 and b2;
end
else
b1:=false;
if b1 then
begin
sum:=;
j:=k;
inc(k);
while k<=tot do
begin
str:=s[k];
if judge(str)= then inc(sum);
if sum= then
if (str[]='L') or (str[]='N') then
begin
for i:=j+ to k- do
if judge(s[i])<= then warn2(i);
c:=d;
exit(true);
end;
if str[]='N' then dec(sum);
inc(k);
end;
if k>tot then
for i:=j+ to tot do
if judge(s[i])<= then warn2(i);
end;
end
else if judge(str)= then //else语句
begin
exit(false);
end
else if judge(str)= then //end if语句
begin
exit(false);
end;
inc(k);
end;
end;
procedure main;
var i,l:longint;
bool:boolean;
begin
l:=length(s[]);
fillchar(b,sizeof(b),false);
for i:= to l do
if (s[][i]>='A') and (s[][i]<='Z') then
b[ord(s[][i])-]:=true;
i:=;
bool:=dfs(i,b);
end;
begin
init;
main;
end.
05-11 19:33