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 ;
}
随机推荐
- keil中如何得知所编译程序所占空间大小?
keil编译后出现Program Size: data=21.0 xdata=0 code=2231. 这表明 data= 21.0 数据储存器内部RAM占用21字节, xdata=0 数据 ...
- LeetCode7:Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...
- oracle学习 十一 包+复合类型+自定义异常(持续更新)
在这里讲一下包的概念, 二话不说上个例子 包头: create or replace package pck_test is procedure proc_report_salary(name nva ...
- CSS单词换行and断词
背景 某天老板在群里反馈,英文单词为什么被截断了? 很显然,这是我们前端的锅,自行背锅.这个问题太简单了,css里加两行属性,分分钟搞定. 1 2 word–break: keep–all; wo ...
- Castle IOC容器构建配置详解(二)
主要内容 1.基本类型配置 2.Array类型配置 3.List类型配置 4.Dictionary类型配置 5.自定义类型转换 一.基本类型配置 在Castle IOC的配置文件中,大家可能都已经注意 ...
- OC:通讯录实战
实战(使用OC的知识制作一个简易通讯录) //语法糖.笑笑语法 // NSString * string = [NSString stringWithFormat:@"string" ...
- Hibernate 与 Spring 的整合
刚刚学习了hibernate和Spring的整合,现在来总结一下. 以实现一个功能为例,与大家分享一下整个过程. 需要实现的功能:建立一个Person类,该类包括name,sex,age,birtha ...
- mybatis 注解快速上手
一.mybatis 简单注解 关键注解词 : @Insert : 插入sql , 和xml insert sql语法完全一样 @Select : 查询sql, 和xml select sql语法完全一 ...
- 初步认识pg_control文件之一
这个据说是PostgreSQL的control file. 到底如何呢,先看看改名后如何,把pg_control文件改名,然后启动 Postgres,运行时得到信息: [postgres@pg101 ...
- PL/pgSQL学习笔记之五
http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 39.3. 声明 块中使用的所有的变量必须在块的声明节中进行声明 ...