题解:

傻逼模拟题

果断的复制了题解(还没有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.

bzoj1238的更多相关文章

随机推荐

  1. C#清除HTML样式

    C#清除HTML样式 需求说明: 网站开发时我们经常用一个富文本控件让用户自己编辑新闻内容和新闻格式,然后将HTML代码一并保存到数据库中. 然后显示文章列表的时候只需要显示一个文章摘要,所以我们就计 ...

  2. Very Good Article on How Git Commands Work

    http://stackoverflow.com/questions/30038999/differences-between-commit-commit-and-push-commit-and-sy ...

  3. Python自学:第二章 修改字符串的大小写 titile.()、upper()、lower()

    title.():首字母大写 upper():全大写 lower():全小写 ada lovelace:人名,传控计算机创始人 name = "ada lovelace" prin ...

  4. 表结构中updated_time设计为ON UPDATE CURRENT_TIMESTAMP时,使用过程的一个坑

    一.mysql表结构中存在如下设计时 表结构中updated_time设计为ON UPDATE CURRENT_TIMESTAMP时,如下 `updated_time` datetime NOT NU ...

  5. LeetCode--345--反转字符串中的元音字母

    问题描述: 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: &quo ...

  6. 编译spark-0.9.1

    准备工作:注意 spark-0.9.1 要求 scala-2.10.x 版本,sbt-0.12.4版本. centos 6.4 x64 系统,java 1.7.0 x64 1,安装 scala-2.1 ...

  7. [LintCode] Number of Islands(岛屿个数)

    描述 给一个01矩阵,求不同的岛屿的个数. 0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛.我们只考虑上下左右为相邻. 样例 在矩阵: [ [1, 1, 0, 0, 0], [0, 1, ...

  8. css之transform属性

    定义元素的旋转(rotate),缩放(scale),移动(translate),倾斜(skew) rotate rotate(angle) 定义 2D 旋转,在参数中规定角度. rotate3d(x, ...

  9. CF数据结构练习

    1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...

  10. Spring Boot集成Thymeleaf

    Thymeleaf是一个java类库,是一个xml/xhtml/html5的模板引擎,可以作为mvc的web应用的view层.Thymeleaf提供了额外的模块与Spring MVC集成,所以我们可以 ...