博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 1244
阅读量:5098 次
发布时间:2019-06-13

本文共 2657 字,大约阅读时间需要 8 分钟。

ZOJ Problem Set - 1244
Definite Values

Time Limit: 2 Seconds     
Memory Limit: 65536 KB

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

//没看清题目,被格式给坑死了 #include 
#include
#include
#include
#include
#include
using namespace std; int rc[30];int main(){ int n; int t=1; char a,b; bool f; int i; while(scanf("%d",&n),n) { memset(rc,0,sizeof(rc)); rc[0]=1; while(n--) { getchar(); scanf("%c = %c",&a,&b); rc[a-'a']=rc[b-'a']; } f=0; printf("Program #%d\n",t++); for(i=0;i<26;i++) if(rc[i]) f=1,printf("%c ",i+'a'); if(!f) printf("none"); printf("\n\n"); }}

转载于:https://www.cnblogs.com/372465774y/archive/2012/07/26/2609372.html

你可能感兴趣的文章
jvm性能调优笔记
查看>>
python学习第三天基本数据类型、格式化输入输出、运算符。流程控制
查看>>
FRM-40654 Record has been updated
查看>>
IDEA03 连接数据库、自动生成实体类
查看>>
保险数据分析
查看>>
字程序级别的重构
查看>>
标准的ajax上传
查看>>
extjs4 折线图(实时动态展现数据)实例
查看>>
测试小技巧之常用工具
查看>>
真有效值与有效值概念
查看>>
poj1470 LCA+RMQ
查看>>
搭建 CentOS 6 服务器(15) - Keepalived、HAProxy、LVS
查看>>
优秀IOS开发网站集合
查看>>
hdu 4451水题
查看>>
博客作业2---线性表
查看>>
右击main 方法运行正常,启动tomcat 后,spring boot 项目 出现参数字符串是乱码的情况...
查看>>
javascript朝花夕拾
查看>>
20135335郝爽 & 20135304刘世鹏 实验一
查看>>
多行文本省略号的实现.html
查看>>
写枚举常量
查看>>