记录编号 |
224130 |
评测结果 |
AAAAAAAAAA |
题目名称 |
树的层次遍历 |
最终得分 |
100 |
用户昵称 |
liu_runda |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.015 s |
提交时间 |
2016-02-15 16:45:57 |
内存使用 |
4.12 MiB |
显示代码纯文本
#include<cstdio>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
struct node{
string s;
int data;int lch,rch,prt;
}tree[100000];
bool cmp(const node &a,const node &b){
if(a.s.size()!=b.s.size())return a.s.size()<b.s.size();
else return a.s<b.s;
}
int len = 0;
int read(){
tree[len].s = "";
char tmp='&';
while(tmp=getchar(),tmp!='(')if(tmp==EOF)return -2;
while(tmp=getchar(),tmp>'9'||tmp<'0')if(tmp==')')return -1;
int num=tmp-'0';
while(tmp=getchar(),tmp<='9'&&tmp>='0')num=num*10+tmp-'0';
tree[len].data = num;
while(tmp=getchar(),tmp!='L'&&tmp!='R')if(tmp==')'){
len++;return 0;
}
tree[len].s+=tmp;
while(tmp=getchar(),tmp=='L'||tmp=='R')tree[len].s+=tmp;
len++;
if(tmp==')')return 0;
while(tmp=getchar(),tmp!=')');
return 0;
}
node tree2[100000];
int main(){
freopen("vlevel.in","r",stdin);
freopen("vlevel.out","w",stdout);
while(1){
lb1:
set<string> dict;
len=0;
if(read()==-2)break;
while(read()!=-1);
sort(tree,tree+len,cmp);
if(tree[0].s.size()){
printf("not complete\n");
continue;
}
for(int i = 0;i<len;++i){
if(dict.count(tree[i].s)){
// printf("%s\n",tree[i].s.c_str());
printf("not complete\n");
goto lb1;
}
dict.insert(tree[i].s);
}string tmp;
for(int i = 1;i<len;++i){
tmp = tree[i].s;
tmp.erase(tmp.end()-1,tmp.end());
if(!dict.count(tmp)){
printf("not complete\n");
goto lb1;
}
}
//不重不少,可以!
for(int i = 0;i<len;++i)printf("%d ",tree[i].data);
printf("\n");
}
fclose(stdin);fclose(stdout);
return 0;
}