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;
}
目录
相关文章
RabbmitMQ 网络分区
RabbmitMQ 网络分区
272 0
|
运维 安全 数据安全/隐私保护
工单系统大揭秘!选择工单系统需注意的关键因素!
这篇内容介绍了工单系统的种类和选择指南。主要类型包括IT工单系统、客户服务工单管理系统、设备维护工单管理系统和全渠道工单系统。选择合适的工单系统需考虑功能需求、企业预算、易用性、系统稳定性、售后服务和技术安全。推荐了Zoho Desk作为好用的工单系统选项,它提供专业服务和免费试用。
482 1
|
存储 Prometheus Kubernetes
对比开源丨Prometheus 服务多场景存储压测全解析
谁不想要一个省心又好用的监控呢?用数据说话,让我们看看不同集群规模下,阿里云Prometheus 服务Vs开源版本的存储性能压测对比吧!
840 99
对比开源丨Prometheus 服务多场景存储压测全解析
|
监控 测试技术
在模型训练中,如何衡量和平衡通用性和特定任务需求的重要性?
在模型训练中,如何衡量和平衡通用性和特定任务需求的重要性?
377 2
|
机器学习/深度学习
while循环
该内容是关于编程中的`while`循环结构介绍。它以markdown格式展示了`while`循环的基本形式:`while(表达式) 语句;`,并提到如果需要多条语句,可以用大括号包裹。接着,提供了两个实例:一是打印1到10的数字,二是逆序输出一个正整数的每一位。每个实例都配有一个展示结果的图片。
247 2
|
存储 编解码 JSON
MP4封装格式
MP4封装格式介绍及解释,本文介绍 mp4 里面各种 box 的作用,包括 mdat box, moov box,mdhd box 等等。
1040 0
|
存储 缓存 安全
JAVA面试:String、StringBuffer和StringBuilder区别
`String`是不可变的,`StringBuffer`和`StringBuilder`是可变的。`String`的不可变性源于其内部的`final char[]`数组,这意味着每次修改都会创建新对象。`StringBuffer`线程安全,方法同步,适合多线程环境,但效率较低;`StringBuilder`非线程安全,无同步,单线程中效率更高。两者初始容量相同,扩容机制也一样。
207 0
|
前端开发 JavaScript API
JavaScript学习笔记(一)promise与async
JavaScript学习笔记(一)promise与async
|
缓存 Java Shell
ThingsBoard详细编译指南2.4.3
ThingsBoard详细编译指南2.4.3
1519 0
|
机器学习/深度学习 搜索推荐
深度学习推荐模型-Wide&Deep
Wide部分主要作用是让模型具备较强的“记忆能力”;Deep部分的主要作用是让模型具有“泛化能力”。
692 0
深度学习推荐模型-Wide&Deep