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

📄 3615760_tle.cpp

📁 北大大牛代码 1240道题的原代码 超级权威
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define  INIT (trie *)malloc(sizeof(trie))

typedef struct node
{
	struct node *next[11];
}trie;

int mark;

void SetNull(trie *t)
{
	int i;

	for (i = 0; i < 11; i++)
		t->next[i] = NULL;
}

void insert(trie *t,char str[])
{
	trie *p;
	int i;

	if (t->next[':'-'0']!=NULL)
		mark = 1;
	if(str[0]==':')
	{
		for (i = 0; i < 11; i++)
			if(t->next[i]!=NULL)
				mark = 1;
	}
	if (t->next[str[0]-'0']==NULL)
	{
		p = INIT;
		SetNull(p);
		t->next[str[0]-'0'] = p;
		if (str[0]==':')
			return ;
		else
			insert(t->next[str[0]-'0'],&str[1]);
	}
	else
	{
		if(str[0]==':')
			return ;
		else
			insert(t->next[str[0]-'0'],&str[1]);
	}
}

void Free(trie *t)
{
	int i;

	for (i = 0; i < 11; i++)
	{
		if (t->next[i]!=NULL)
		{
			Free(t->next[i]);
			t->next[i] = NULL;
		}
	}
}

void input()
{
	int n, i;
	trie *root;
	char num[12];

	scanf("%d",&n);
	mark = 0;
	root = INIT;
	SetNull(root);
	for (i = 0; i < n; i++)
	{
		scanf("%s",num);
		if (mark)
			continue;
		strcat(num,":");
		insert(root,num);
	}
	printf("%s\n",(mark?"NO":"YES"));
	Free(root);
}

int main()
{
	int t;

	scanf("%d",&t);
	while(t--)
		input();
	return 0;
}

⌨️ 快捷键说明

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