TZU2014年省赛个人热身赛1 1264:Definite Values
来源:互联网 发布:北京居住证 知乎 编辑:程序博客网 时间:2024/05/24 15:37
描述
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.
输入
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.
输出
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.
样例输入
4b = ac = dd = be = f1a = b0
样例输出
Program #1a b d Program #2none
题意:a是初始化的,其他都没有初始化,输出最后成功初始化的变量
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int n;char s1[5],s2[5];int hash[100];int main(){ int i,j,cas = 1; while(scanf("%d",&n),n) { memset(hash,0,sizeof(hash)); hash[0] = 1; for(i = 0;i<n;i++) { scanf("%s = %s",s1,s2); if(hash[s2[0]-'a']) hash[s1[0]-'a'] = 1; else hash[s1[0]-'a'] = 0; } printf("Program #%d\n",cas++); int flag = 1; for(i = 0;i<26;i++) { if(hash[i]) { printf("%c ",i+'a'); flag = 0; } } if(flag) printf("none"); printf("\n\n"); } return 0;}
- TZU2014年省赛个人热身赛1 1264:Definite Values
- TZU2014年省赛个人热身赛1 1187:Do the Untwist
- TZU2014年省赛个人热身赛1 1962:Binary Clock
- TZU2014年省赛个人热身赛1 3387:Free Goodies(DP+贪心)
- TZU2014年省赛个人热身赛1 3741:Singlehood Number
- TZU2014年省赛个人热身赛1 1197:Number Guessing
- Definite Values
- fjnu 1673 Definite Values
- TOJ 1594. Definite Values
- hdu 1327 Definite Values
- hdu 1327 Definite Values--map
- 2015年省赛个人热身赛3
- 热身赛
- 热身赛
- 12/9/1 热身赛总结
- 12.3 Definite assignment
- Positive Semi-definite matrix
- Positive-definite matrix
- sqlserver链接数据库
- TZU2014年省赛个人热身赛1 3741:Singlehood Number
- DFS与BFS
- Investigation report of MSSQL data read and write performance
- js回调函数复习
- TZU2014年省赛个人热身赛1 1264:Definite Values
- 运行jsp文件后浏览器出现的是:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
- mysql数据库的基本操作命令
- zoj 3720 几何 判断点在多边形内
- c++ fstream中seekg()和seekp()的用法
- GitHub for Windows 安装失败,An error occurred attempting to install github 的解决办法
- Java模拟HTTP的Get和Post请求(增强) Apache-httpclient
- JAVA设计模式之策略模式(1)
- Oracle表连接操作——Hash Join(哈希连接)上