bzoj1238
题解:
傻逼模拟题
果断的复制了题解(还没有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的更多相关文章
随机推荐
- DAY2 初识python
一.编程语言介绍 1.1 机器语言:直接用计算机能理解的二进制指令编写程序,直接控制硬件 1.2 汇编语言:用英文标签取代二进制指令取编写程序,本质也是在直接控制硬件 1.3 高级语言:用人能理解的表 ...
- d3 parse字符串形式的xml svg and append to element
参考这个方法,但不想修改d3 https://gist.github.com/biovisualize/373c6216b5634327099a 虽然也绕了点弯,但还算很快了,比较满意,也学到了,记下 ...
- d3 data()数据绑定中的key函数
官网https://github.com/d3/d3-selection/blob/master/README.md#selection_data var data = [ {name: " ...
- 使用git命令行解决冲突
文章转载自:https://blog.csdn.net/sureSand/article/details/78765727 使用git和提交的代码有所冲突,用IDE自带的git工具功能多了反而不知道怎 ...
- Linux修改hostname时/etc/hosts、/etc/sysconfig/network ,hostname,三者的区别和联系
[root@localhost /]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.l ...
- Backup and Recovery Types
Physical(Raw) and Logical Backup: 1.Physical backups consist of raw copies of the directories and fi ...
- BAT 大规模Hadoop集群实践
百度高级架构师马如悦:我的Hadoop 2.0 http://www.csdn.net/article/2011-04-28/296869 腾讯大规模Hadoop集群实践 腾讯 hadoop 基线版本 ...
- csu oj 1343 Long Long
Description 现在有两个单调递增序列,第一个序列有N个整数,第二个序列有M个整数,现在你可以从第一个序列中选一个数x,然后从第二个序列中选一个数y,那么有多少种情况满足x+y<=K呢? ...
- MySQL 分页查询和存储过程
一.分页查询 使用limit函数,limit关键字的用法: LIMIT [offset,] rows: offset指定要返回的第一行的偏移量,rows第二个指定返回行的最大数目.初始行的偏移量是0( ...
- 微信公众号使用LocalStorage解决返回缓存问题
在开发微信公众号上应用程序时,遇到了一个普遍的问题,从A页跳转到B页后,再由B页跳转回A页,A要要保持跟跳转前一致,通过LocalStorage可以解决. LocalStorage,很好的解决了返回的 ...