乍一看以为是图论题,结果发现就是道水题,依次枚举下完事了
#include<cstdio>
#include<cstring>
int main()
{
int n, cs = 0;
bool b[26];
char c1[2], c2[2];
while (scanf("%d", &n), n)
{
getchar();
memset(b, 0, sizeof(b));
b[0] = true;
while (n--)
{
scanf("%s %*s %s", c1, c2);
b[c1[0] - 'a'] = b[c2[0] - 'a'];
}
printf("Program #%d\n", ++cs);
int i;
bool flag = false;
for (i = 0; i < 26; i++)
if (b[i])
{
printf("%c ", i + 'a');
flag = true;
}
if (!flag)
puts("none\n");
else
puts("\n");
}
return 0;
}