QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#11026. 指针分析

统计

指针分析旨在确定程序执行过程中,特定指针变量可访问哪些对象,这是静态程序分析的基础部分之一。现在,请你对测试数据执行上下文不敏感的指针分析。

程序包含 26 个对象(用小写字母表示),每个对象有 26 个成员变量(即字段,也是指向某些对象的指针,同样用小写字母表示)。同时,程序中有 26 个全局指针(用大写字母表示)。

程序中有四种语句。我们使用 [Variable] 表示指针名称,[Field] 表示成员变量名称,[Object] 表示对象。

格式 示例 描述
[Variable] = [Object] A = x 指针 A 可以指向对象 x(即 x 可通过 A 访问)
[Variable] = [Variable] A = B 指针 A 可以指向所有可通过 B 访问的对象
[Variable].[Field] = [Variable] A.f = B 对于每个可通过 A 访问的对象 o,其成员变量 f 可以指向所有可通过 B 访问的对象
[Variable] = [Variable].[Field] A = B.f 对于每个可通过 B 访问的对象 oA 可以指向所有可通过对象 o 的成员变量 f 访问的对象

上下文不敏感的指针分析假设程序中的语句会以任意顺序执行足够多次。例如,在以下两个程序中,AB 都可以指向对象 x 和对象 o。这是因为在现实中,确切的执行顺序和语句执行次数难以预测。

第一段程序 第二段程序
A = o B = A
A = x A = x
B = A A = o

现在要求你对给定的包含 $N$ 条语句的程序执行上下文不敏感的指针分析,并输出每个指针可以指向的对象。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 200$),表示程序中的语句数量。等号 = 前后各有一个空格。 接下来的 $N$ 行,每行包含一条语句。

输出格式

输出应包含 26 行。 在第 $i$ 行,输出第 $i$ 个指针的名称(即第 $i$ 个大写字母),后跟一个冒号 : 和一个空格,然后按字母顺序排列该指针可访问的对象。

样例

输入格式 1

5
B.f = A
C = B.f
C = x
A = o
B = o

输出格式 1

A: o
B: o
C: ox
D:
E:
F:
G:
H:
I:
J:
K:
L:
M:
N:
O:
P:
Q:
R:
S:
T:
U:
V:
W:
X:
Y:
Z:

输入格式 2

4
A = o
B.f = A
C = B.f
C = g

输出格式 2

A: o
B:
C: g
D:
E:
F:
G:
H:
I:
J:
K:
L:
M:
N:
O:
P:
Q:
R:
S:
T:
U:
V:
W:
X:
Y:
Z:

输入格式 3

3
A = o
B = A
A = x

输出格式 3

A: ox
B: ox
C:
D:
E:
F:
G:
H:
I:
J:
K:
L:
M:
N:
O:
P:
Q:
R:
S:
T:
U:
V:
W:
X:
Y:
Z:

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.