RT,求助,代码如下。
本地用的是 Dev-C++ and 洛谷 IDE ,均可过。
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
const int N=26;
int n,tot;char a,b,c;
map<char,int> mp;
map<int,char> mp2;
struct Node{int l,r;}sz[N+5];
int Cal(char h)
{
if(mp[h]==0)
{tot++,mp[h]=tot,mp2[tot]=h;}
return mp[h];
}
void Pre(int now)
{
cout<<mp2[now];
if(sz[now].l!=Cal('*')) Pre(sz[now].l);
if(sz[now].r!=Cal('*')) Pre(sz[now].r);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;cin>>b>>c;
sz[Cal(a)].l=Cal(b);
sz[Cal(a)].r=Cal(c);
}
Pre(1);
return 0;
}
拜谢。