Phone List
1. Emergency 911
2. Alice 97 625 999
3. Bob 91 12 54 26
In
this case, it’s not possible to call Bob, because the central would
direct your call to the emergency line as soon as you had dialled the
first three digits of Bob’s phone number. So this list would not be
consistent.
first line of input gives a single integer, 1 <= t <= 40, the
number of test cases. Each test case starts with n, the number of phone
numbers, on a separate line, 1 <= n <= 10000. Then follows n
lines with one unique phone number on each line. A phone number is a
sequence of at most ten digits.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cstdlib>
using namespace std;
const int INF=0x5fffffff;
const int MS=;
const double EXP=1e-; char str[MS][]; int cmp(const void *a,const void *b)
{
return strcmp((char *)a,(char *)b);
} int main()
{
int T;
int n,i;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%s",str[i]);
//sort(str,str+n,cmp);
qsort(str,n,sizeof(str[]),cmp);
int ok=;
for(i=;i<n&&ok;i++)
{
if(strncmp(str[i-],str[i],strlen(str[i-]))==)
ok=;
}
if(ok)
puts("YES");
else
puts("NO");
}
return ;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cstdlib>
using namespace std;
const int INF=0x5fffffff;
const int MS=;
const double EXP=1e-; struct node
{
bool have;
node * next[];
}nodes[MS];
node *root;
bool flag;
int cnt;
node * add_node(int c)
{
node *p=&nodes[c];
for(int i=;i<;i++)
p->next[i]=NULL;
p->have=false;
return p;
}
void insert(char *str)
{
node *p=root,*q;
int len=strlen(str);
for(int i=;i<len;i++)
{
int id=str[i]-'';
if(p->next[id]==NULL)
{
q=add_node(cnt++);
p->next[id]=q;
}
// if(p->have==true)
// flag=true;
p=p->next[id];
if(p->have==true)
flag=true;
}
p->have=true;
for(int i=;i<;i++)
{
if(p->next[i]!=NULL)
{
flag=true;
break;
}
}
}
int main()
{
int i,n,t;
char str[];
scanf("%d",&t);
while(t--)
{
cnt=;
root=add_node(cnt++);
flag=false;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%s",str);
if(!flag)
{
insert(str);
}
}
if(flag==false)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
随机推荐
- Spark的优点
Spark的一站式解决方案,非常之具有吸引力,毕竟啊,任何公司都想用统一的平台去处理遇到的问题,减少开发和维护的人力成本和部署平台的物力成本. 当然,Spark并没有以牺牲性能为代价.相反,在性能方面 ...
- Axis2与Web项目整合
一.说明: 上一篇介绍了通过使用Axis2来发布和调用WebService,但是是把WebService发布在Axis2提供的项目中,如果我们需要在自己的Web项目中来使用Axis2发布WebServ ...
- cvc-elt.1: Cannot find the declaration of element 'beans'
@(编程) 现象描述 导入的一个eclipse项目报错,各种方法都无法解决,报错信息如下: cvc-elt.1: Cannot find the declaration of element 'bea ...
- 常见的mongo shell命令
启动mongo shell 在windows下,双击mongo.exe可以启动mongo shell 查询库.表及选择库 查询所有库命令: show dbs 应用某一个db use jxs_datab ...
- oracle学习 六 删除表空间,数据文件的语句以及导入导出dmp文件的方法(持续更新中)
要想删除表空间就要先删除数据文件 例如这个例子 CREATE TABLESPACE STHSGIMGDB_SPACE11 DATAFILE 'D:\ORACLEDATABASE\JinHuaDataB ...
- QTbaWidget控件几个例程 【worldsing笔记】
Qt Creator自带的 QTabWidget控件几个例程 在Qt Windos版本安装后,在Example目录可以找到与QTabWidget相关的工程Demo,如果按默认安装的话他们分别是: ...
- svg base64
好多h5页面有出现data:image/png;base64,后面跟了一串类似乱码的字母 查了下原来这也是svg或者是图片 <img src=“data:image/png;base64,iVB ...
- 在TFS2013上删除项目
TFSDeleteProject 会永久性损坏团队项目,之后无法恢复该项目. 您应该在使用 TFSDeleteProject 之前备份所有重要的项目数据. 若要使用 TFSDeleteProject ...
- UVaLive 7512 November 11th (思维漏洞)
题意:给定n*m个座椅,然后有b个是坏的,要做人,并且两个人不能相邻,问你最多坐多少人,最少坐多少人. 析:这个题其实并不难,只要当时一时没想清楚,结果就一直WA,就是最少的情况时,其实一个人可以占三 ...
- Objc基础学习记录3
在学习Objective-c中, 数组 1.NSArray, 这是一个不可变的数组,不能修改和删除其中的对象,可以存储任意objective的对象指针. 不能存储int,char类型的,,需要转换为需 ...