⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1167.cpp

📁 自己的ac代码 在acm.zju.edu.cn 上的题目
💻 CPP
字号:
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
queue<int>qu;
struct node
{
	int lson,rson,data;
};
node T[10000];
int tot;
char s[1000];
int flag;
int getnum(char *s)
{
	int i=0;
	int ret=0;
	while(s[i]>='0' && s[i]<='9')
	{
		ret=ret*10+int(s[i])-48;
		i++;
	}
	return ret;
}
void ins(int t,int num,char *s)
{
	if(s[0]==')')
	{
		if(T[t].data!=-1)flag=0;
		T[t].data=num;
		return ;
	}
	if(s[0]=='L')
	{
		if(T[t].lson==0)
		{
			tot++;
			T[tot].lson=0;
			T[tot].rson=0;
			T[tot].data=-1;
			T[t].lson=tot;
		}
		ins(T[t].lson,num,s+1);
		return ;
	}
	if(s[0]=='R')
	{
		if(T[t].rson==0)
		{
			tot++;
			T[tot].lson=0;
			T[tot].rson=0;
			T[tot].data=-1;
			T[t].rson=tot;
		}
		ins(T[t].rson,num,s+1);
		return ;
	}
}
void output()
{
	
	while(!qu.empty())qu.pop();
	qu.push(1);
	int tmp;
	int a[1000];int c=0,i;
	while(!qu.empty())
	{
		tmp=qu.front();qu.pop();a[c++]=tmp;
		if(T[tmp].data==-1){flag=0;break;}
		if(T[tmp].lson!=0)qu.push(T[tmp].lson);
		if(T[tmp].rson!=0)qu.push(T[tmp].rson);
	}
	if(flag==0)
		printf("not complete\n");
	else
	{
		for(i=0;i<c;i++)
		{
			if(i!=0)printf(" ");
			printf("%d",T[a[i]].data);
		}
		printf("\n");
	}
}







int main()
{
	int i,j,k;
	
	while(scanf("%s",s)!=EOF)
	{
		tot=1;
		T[tot].lson=0;
		T[tot].rson=0;
		T[tot].data=-1;
		flag=1;
		while(strcmp(s,"()")!=0)
		{
			int num=getnum(s+1);
			for(j=0;s[j]!=',';j++);
			ins(1,num,s+j+1);
			scanf("%s",s);
		}
		output();
	}
	return 0;
}


			



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -