hdu1327 Definite Values

简介: hdu1327 Definite Values

Problem Description

A common error in programming is to use variables that have not been initialized before. For example, in C and C++, all variables have an indefinite value after declaration - their value can be anything. Thus, the following program


main()

{

int x;

printf("%d\n",x);

}


could print any number. But even in languages such as Pascal, where all values are initialized to zero, it is useful to give variables definite values before using them, the avoid side effects when your code portion is placed into a different context.


Generally, the problem of deciding for a given program whether all variables have been assigned values before they are read out, is undecidable. But if you, as in this problem, consider only a sequence of assignments, the problem becomes solvable.

 

 

Input

The input contains several program parts. Each part starts with a number n on a line by itself, the number of lines in the program part. The following n lines contain each an assignment of the form "variable1 = variable2", where the variablei's are lower-case letters.


The input is terminated by a test case starting with n = 0.

 

 

Output

Assume that before the execution of the given program part, variable a has some definite value, while all other variables are undefined. You have to print the names of the varaibles which have a definite value after the execution of the program part. More specifically, format your output as follows.


For each program part in the input, first print the number of the program, as shown in the sample output. Then print a line containing the names of the variables which have a definite value after the execution of the given program part. Print them in alphabetically sorted order, and leave one blank after each variable name. If none of the variables has a definite value after the execution of the program part, print the word "none".


Print a blank line after each test case.

 

 

Sample Input

 

4 b = a c = d d = b e = f 1 a = b 0

 

 

Sample Output

 

Program #1 a b d Program #2 none

 

 

Source

Southwestern Europe 1997, Practice

 

水题,格式是个坑,输出的每一个字母后面都带空格。

 

代码如下:

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int i,n,T=0;
    while(scanf("%d",&n)!=EOF&&n)                                   //多组试例
    {
    T++;
    int a[26]={0};
    a[0]=1;
    //for(i=0;i<26;i++)
    //    printf("%d",a[i]);
    getchar();
    while(n--)
    {
        char str[5];
    gets(str);
    a[str[0]-'a']=a[str[4]-'a'];
    }
    printf("Program #%d\n",T);
    int f=0;
for(i=0;i<26;i++)
if(a[i]==1)
{
    //if(f==1) printf(" ");
    printf("%c ",i+'a');                                    //每一个输出后都带空格
    f=1;
}
if(f==0) printf("none");
printf("\n\n");
    }
return 0;
}
目录
相关文章
|
12月前
|
存储 编解码 人工智能
Sora正式上线!145元就能体验,内置剪辑神器让你秒变视频大师
Sora正式上线,145元即可体验。内置剪辑工具,助你快速生成视频,支持多种分辨率和长达20秒的视频输出。新增故事板编辑、场景混合等功能,让创作更便捷。不过,模型仍存在物理理解不足等问题,需谨慎期待。Sora现已在美国及多数国际市场推出,但中国地区暂不支持。
332 3
Sora正式上线!145元就能体验,内置剪辑神器让你秒变视频大师
|
存储 算法 搜索推荐
深度优先遍历与广度优先遍历:理解它们的原理与差异
深度优先遍历与广度优先遍历:理解它们的原理与差异
|
存储 Linux 数据库
在Linux中,什么是快照备份?
在Linux中,什么是快照备份?
|
设计模式 Java 中间件
静态代理和动态代理的区别以及实现过程
这篇文章通过示例代码讲解了静态代理和动态代理在Java中的使用方式和区别,重点介绍了动态代理的实现原理及其在Spring框架中的应用。
静态代理和动态代理的区别以及实现过程
|
小程序 前端开发 数据库
【微信小程序2】云数据库:利用addField在返回记录中增加新字段
【微信小程序2】云数据库:利用addField在返回记录中增加新字段
325 4
计算机网络——物理层-信道的极限容量(奈奎斯特公式、香农公式)
计算机网络——物理层-信道的极限容量(奈奎斯特公式、香农公式)
719 0
|
数据可视化 索引 Python
Pandas 2.2 中文官方教程和指南(二十·二)(3)
Pandas 2.2 中文官方教程和指南(二十·二)
252 0
|
JSON Java Maven
GraphQL(四)自定义标量[Scalar]详解
本文介绍GraphQL的标量拓展、自定义标量的定义及使用。 从版本 3.9.2 开始,DGS 框架具有graphql-dgs-extended-scalars模块。此模块提供自动配置,将自动注册库中定义的标量扩展 `com.graphql-java:graphql-java-extended-scalars`。
|
机器学习/深度学习 存储 算法
(建议收藏)一文多图,彻底搞懂Floyd算法(多源最短路径)
在图论中,在寻路最短路径中除了Dijkstra算法以外,还有Floyd算法也是非常经典,然而两种算法还是有区别的,Floyd主要计算多源最短路径。
10834 2
(建议收藏)一文多图,彻底搞懂Floyd算法(多源最短路径)
|
安全 开发工具
【干货】验证码的常见类型总结
验证码是一种区分用户是计算机和人的公共全自动程序。简单来说,验证码就是验证操作是人还是机器。下面我就总结一下常见的验证码类型都有哪些?
【干货】验证码的常见类型总结