变量就未赋值和已赋值两种状态。所谓赋值就是把一个变量的状态复制到另一个变量。仅此而已。因此用简单的模拟就可以做出。
#include<iostream>
using namespace std;
void Restore(int map[]);
int main()
{
char b[3];
int data,lines;
int map[26];
cin>>data;
while(data>0)
{
data--;
Restore(map);
cin>>lines;
//Analysis the valuing
while(lines>0)
{
lines--;
cin>>b;
map[b[0]-'a']=map[b[2]-'a'];
}
//Output map
int sum=0;
for(int temp=0;temp<26;temp++)
{
if(map[temp])
{
if(sum>0) cout<<' ';
cout<<(char)('a'+temp);
sum++;
}
}
if(0==sum) cout<<"none";
cout<<endl;
}
return 0;
}
void Restore(int map[])
{
int temp;
map[0]=1;
for(temp=1;temp<26;temp++) map[temp]=0;
}
using namespace std;
void Restore(int map[]);
int main()
{
char b[3];
int data,lines;
int map[26];
cin>>data;
while(data>0)
{
data--;
Restore(map);
cin>>lines;
//Analysis the valuing
while(lines>0)
{
lines--;
cin>>b;
map[b[0]-'a']=map[b[2]-'a'];
}
//Output map
int sum=0;
for(int temp=0;temp<26;temp++)
{
if(map[temp])
{
if(sum>0) cout<<' ';
cout<<(char)('a'+temp);
sum++;
}
}
if(0==sum) cout<<"none";
cout<<endl;
}
return 0;
}
void Restore(int map[])
{
int temp;
map[0]=1;
for(temp=1;temp<26;temp++) map[temp]=0;
}