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的更多相关文章
随机推荐
- echarts 拼图和折线图的封装 及常规处理
1.html <div id="wrap"></div> 2.js ; (function ($) { $.fn.extend({ echartsPie: ...
- 牛客国庆集训派对Day3 A Knight
Knight 思路: bfs打表找规律 如下图 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) ...
- Codeforces 833 C - Ever-Hungry Krakozyabra
思路: 首先,inedible tails 的个数最多为C(18+9,9)个(用隔板法),所以我们暴力出所有的 inedible tails,然后检查一下在[L, R]这段区间是否存在这个inedib ...
- python中函数与函数式编程(一)
在学习之前,我们先去区分面对对象.面对过程.函数式编程他们之间的区别,从改图可以看出,他们之间不是完全相同的,也不是没有任何相同点的 1.函数和过程的基本认识 def func1(): "& ...
- jquery如何获取checkbox的值
jquery如何获取checkbox的值 一.总结 一句话总结:就是通过jquery获取哪些对应name的checkbox,然后找出:check(被选中的),然后通过jquery的each遍历获取这些 ...
- 20165327《Java程序设计》实验一 Java开发环境的熟悉 实验报告
20165327<Java程序设计>实验二 <Java面向对象程序设计>实验报告 实验二 <Java面向对象程序设计> 一.实验报告封面 课程:Java程序设计 班 ...
- 20165303 2017-2017-2《Java程序设计》课程总结
1.我期待的师生关系 20165303我期望的师生关系 2.学习基础和C语言基础调查 20165303学习基础和C语言基础调查 3.linux安装及学习 20165303 预备作业3 Linux安装及 ...
- 怎样在winform中上传图片
http://jingyan.baidu.com/article/b7001fe157d6b60e7382dd7f.html 因为WinForm都是运行在本地的,而我们的网站一般都是布署在服务器上,运 ...
- ubuntu+anaconda
1.下载anaconda 查看ubuntu是32位还是64位 命令: uname -m 如果显示i686,你安装了32位操作系统 如果显示 x86_64,你安装了64位操作系统 uname -a 查看 ...
- python模块--pickle&json&shelve
使用file文件处理时,写入的必须是str ,否则会报错. 例如:要把一个字典写入文件,写入时会报错 ,就算转换成str格式写入,读取的时候也不能按照dict格式读. >>> inf ...