题意:
A,B,C,D…为全局指针,
a,b,c,d…为对象,
a.f,b.f,c.f,d.f…为对象的指针,
A.f,B.f,C.f,D.f…为指向对象的对应指针。
然后一堆语句,等于号是指向的意思,顺序无关,求每个全局指针可能指向过多少个对象。
思路:
被A.f,B.f这些搞蒙了。。。
其实你可以把这个就当做一个新指针,当然前提是全局指针本身要指向了对象。
比如A->o,那么A.f就等价于o.f
如果A没有指向对象,那么A.f就是空指针。
每个指针指向过多少对象可以用bitset维护(数组也可),
因为顺序无关,所以跑个很多遍就好了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include <unordered_map>
#include <map>
#include <string>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
const int maxn = 1005 + 7;
struct Node {
int id;
int A,B,f;
}nodes[maxn];
bitset<26>a[26],b[26][26];
int main() {
int n;scanf("%d",&n);
for(int i = 1;i <= n;i++) {
char s1[10],s2[10];
scanf("%s = %s",s1 + 1,s2 + 1);
if(s1[2] == '.') {
nodes[i].id = 3;
nodes[i].A = s1[1] - 'A';
nodes[i].f = s1[3] - 'a';
nodes[i].B = s2[1] - 'A';
} else if(s2[2] == '.') {
nodes[i].id = 4;
nodes[i].A = s1[1] - 'A';
nodes[i].B = s2[1] - 'A';
nodes[i].f = s2[3] - 'a';
} else if(s2[1] <= 'z' && s2[1] >= 'a') {
nodes[i].id = 1;
nodes[i].A = s1[1] - 'A';
nodes[i].B = s2[1] - 'a';
} else {
nodes[i].id = 2;
nodes[i].A = s1[1] - 'A';
nodes[i].B = s2[1] - 'A';
}
}
for(int i = 1;i <= 1000;i++) {
for(int j = 1;j <= n;j++) {
int x = nodes[j].A,y = nodes[j].B,z = nodes[j].f;
int id = nodes[j].id;
if(id == 1) {
a[x][y] = 1;
} else if(id == 2) {
a[x] |= a[y];
} else if(id == 3) {
for(int k = 0;k < 26;k++) {
if(a[x][k]) {
b[k][z] |= a[y];
}
}
} else if(id == 4) {
for(int k = 0;k < 26;k++) {
if(a[y][k]) {
a[x] |= b[k][z];
}
}
}
}
}
for(int i = 0;i < 26;i++) {
printf("%c: ",i + 'A');
for(int j = 0;j < 26;j++) {
if(a[i][j]) printf("%c",j + 'a');
}
printf("\n");
}
return 0;
}