求调,谢谢
查看原帖
求调,谢谢
355521
rainbow_star楼主2021/11/10 20:06
#include<iostream> 
#include<cstdio>
#include<cstring> 
using namespace std;
long long t,n,l,m;
bool front,cunzai;
char num[11];
struct NODE
{
	long long son[10];
	bool flag;
	NODE()
	{
		int i;
		for(i=0;i<10;i++)
			son[i]=0;
		flag=false;
	}
}trie[1000001];
int main()
{
	long long i,j,k;
	scanf("%lld",&t);
	for(i=1;i<=t;i++)
	{
		scanf("%lld",&n);
		l=0;//已经存有的节点 
		
		front=false;
		for(j=1;j<=n;j++)
		{
			m=0;//当前节点 
			cunzai=false;
			scanf("%s",num);
			if(front==false)
			{
				for(k=0;k<strlen(num);k++)
				{
					if(trie[m].son[num[k]-'0']==0)//不存在节点 
					{
						cunzai=true;
						l++;
						trie[m].son[num[k]-'0']=l;
					}
					m=trie[m].son[num[k]-'0'];
					if(trie[m].flag==true)
					{
						printf("YES\n");
						front=true;
						break;
					}
					if(k==(strlen(num)-1))
						trie[m].flag=true;
				}
			}
			if(cunzai==false&&front==false)
			{
				printf("YES\n");
				front=true;
			}
		}
		if(front==false)
			printf("NO\n");
		for(j=0;j<=l;j++)
		{
			for(k=0;k<10;k++)
				trie[j].son[k]=0;
			trie[j].flag=false;
		}
	}
	return 0;
}
2021/11/10 20:06
加载中...