#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
struct node{
string num;
string str;
}tree[1000];
map<string,int>mymap;
int cnt;
string first;
bool cmp(node a,node b){
if(a.str.length()==b.str.length())
return a.str<b.str;
return a.str.length()<b.str.length();
}
void input(){
string ss=first;
cnt=0;
while(ss!="()"){
int pos=(int)ss.find(",");
tree[cnt].num=ss.substr(1,pos-1);
tree[cnt].str=ss.substr(pos+1,ss.length()-pos-2);
mymap[tree[cnt].str]++;
cnt++;
cin>>ss;
}
}
int iscomplete()
{
if(tree[0].str.length()!=0)
return 0;
string ss;
for(int i=1;i<cnt;i++)
{
ss=tree[i].str.substr(0,tree[i].str.length()-1);
//cout<<tree[i].str<<" "<<mymap.count(tree[i].str)<<endl;
if(mymap.count(ss)==0||mymap[tree[i].str]>1)
return 0;
}
return 1;
}
void computing(){
sort(tree,tree+cnt,cmp);
if(!iscomplete())
{
cout<<"not complete"<<endl;
return ;
}
for(int i=0;i<cnt-1;i++)
cout<<tree[i].num<<" ";
cout<<tree[cnt-1].num<<endl;
}
int main(){
while(cin>>first){
mymap.clear();
input();
computing();
}
return 0;
}
uva122
最新推荐文章于 2021-03-17 10:19:50 发布