| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
就算t死了,也要把这道题a了#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
bool end1;
node *next[10];
int num;
void init(){
end1=false;
for(int i=0;i<10;i++)
next[i]=NULL;
num=0;
}
};
node temp[100000];
node *root;
int flag,count1;
void insert1(char *s)
{
//int len=strlen(s);
node *p=root;
for(int i=0;s[i];i++)
{
int a=s[i]-'0';
if(p->next[a]==NULL)
p->next[a]=temp+count1,count1++;
p=p->next[a];
p->num++;
if(p->end1)
{
flag=1;
return;
}
}
p->end1=true;
if(p->num>1)
{
flag=1;
return;
}
}
void init()
{
for(int i=0;i<100000;i++)
temp[i].init();
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
count1=0;
init();
root=temp+count1;
count1++;
scanf("%d",&n);
flag=0;
char c[20];
for(int i=0;i<n;i++)
{
scanf("%s",c);
if(!flag)
insert1(c);
}
if(flag)
printf("NO\n");
else printf("YES\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator