fjnu 1673 Definite Values
来源:互联网 发布:淘宝鱼大的手办 编辑:程序博客网 时间:2024/05/05 09:43
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
",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
4b = ac = dd = be = f1a = b0
Sample Output
Program #1a b dProgram #2none
KEY:这题以前说过了,不再说了……
Source:
#include<iostream>
#include<algorithm>
using namespace std;
struct node
...{
char c;
int flag;
};
class List
...{
node elem[30];
public:
List()
...{
int i;
for(i=1;i<=26;i++)
...{
elem[i].c='a'+i-1;
elem[i].flag=0;
}
elem[1].flag=1;
}
int find(char x);
void insert(char A,char B);
void output();
};
int List::find(char x)
...{
if(elem[x-96].flag==1) return 1;
else return 0;
}
void List::insert(char A,char B)
...{
if(find(A)&&find(B)) return ;
if(find(A)&&!find(B))
...{
elem[A-96].flag=0;
return ;
}
if(!find(A)&&find(B))
...{
elem[A-96].flag=1;
return ;
}
if(!find(A)&&!find(B)) return ;
}
void List::output()
...{
int t=0;
int i;
for(i=1;i<=26;i++)
if(elem[i].flag==1)
...{
cout<<elem[i].c<<" ";
t++;
}
if(t==0)
...{
cout<<"none"<<endl;
return ;
}
cout<<endl;
}
int main()
...{
// freopen("1673.in","r",stdin);
int T=1;
int N;
char A,B;
int q;
while(scanf("%d ",&N)!=EOF)
...{
if(N==0) break;
cout<<"Program #"<<T++<<endl;
List L;
for(q=1;q<=N;q++)
...{
scanf("%c = %c ",&A,&B);
L.insert(A,B);
}
L.output();
cout<<endl;
}
return 0;
}
- fjnu 1673 Definite Values
- Definite Values
- TOJ 1594. Definite Values
- hdu 1327 Definite Values
- hdu 1327 Definite Values--map
- TZU2014年省赛个人热身赛1 1264:Definite Values
- FJNU
- 12.3 Definite assignment
- Positive Semi-definite matrix
- Positive-definite matrix
- Positive-definite kernel
- Definite awe-inspiring
- values
- positive definite quadratic form and positive definite matrix
- Javascript the definite guide: CH01
- 正定矩阵(Positive-definite Matrix)
- 正定矩阵 Positive definite matrix
- 正定矩阵(definite matrix)
- fjnu 1669 Scramble Sort
- 多一个选择是好是坏?
- vc6中使用数字签名
- fjnu 1670 Geometry Made Simple
- 深入浅出C#2008从入门到提高Step By Step(五)Windows应用程序常用控件类(5)-RadioButton
- fjnu 1673 Definite Values
- 关于自由,关于开源
- c中如何打印函数调用堆栈? - C/C++ - ChinaUnix.net
- fjnu 1671 Carbon Dating
- fjnu 1672 URLs
- 日记第一篇
- 用 Graphviz 可视化函数调用
- ListCtrl Checkbox多选问题
- 错误:界面贴图用gif而不用bmp