sdutoj 2151 Phone Number
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2151
Phone Number
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Given N phone numbers, your task is to find whether there exits two numbers A and B that A is B’s prefix.
输入
The first line of input in each test case contains one integer N (0<N<1001), represent the number of phone numbers.
The next line contains N integers, describing the phone numbers.
The last case is followed by a line containing one zero.
输出
示例输入
2
012
012345
2
12
012345
0
示例输出
NO
YES
提示
来源
示例程序
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; struct node
{
int count;
node *child[];
node()
{
count=;
int i;
for(i=; i<; i++)
child[i]=;
}
}; node *current, *newnode; void insert(node *root, char *ss)
{
//printf("%s*****\n",ss);
int i, m;
current=root;
for(i=; i<strlen(ss); i++)
{
m=ss[i]-'';
if(current->child[m]!=NULL)
{
current=current->child[m];
++(current->count);
}
else
{
newnode=new node;
++(newnode->count);
current->child[m]=newnode;
current=newnode;
}
}
} int search(node *root, char *ss)
{
//printf("%s*****\n",ss);
int i, m;
current=root;
for(i=; i<strlen(ss); i++)
{
m=ss[i]-'';
if(current->child[m]==NULL)
return ;
current=current->child[m];
}
return current->count;
} int main()
{
char str[], s[][];
int t, flag, i;
while(scanf("%d",&t))
{
if(t==) break;
flag=;
node *root=new node;
for(i=; i<t; i++)
{
scanf("%s",str);
strcpy(s[i], str);
//puts(s[i]);
insert(root, str);
}
for(i=; i<t; i++)
{
if(search(root, s[i])-)
{
flag=;
break;
}
}
if(flag==) printf("YES\n");
else printf("NO\n");
}
return ;
}
sdutoj 2151 Phone Number的更多相关文章
- sdutoj 2623 The number of steps
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2623 The number of steps ...
- sdutoj 2610 Boring Counting
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2610 Boring Counting Time ...
- sdutoj 2609 A-Number and B-Number
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2609 A-Number and B-Numbe ...
- sdutoj 2624 Contest Print Server
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624 Contest Print Server ...
- sdutoj 2608 Alice and Bob
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...
- sdutoj 2606 Rubik’s cube
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2606 Rubik’s cube Time Li ...
- sdutoj 2605 A^X mod P
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2605 A^X mod P Time Limit ...
- sdutoj 2604 Thrall’s Dream
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2604 Thrall’s Dream Time ...
- sdutoj 2607 Mountain Subsequences
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607 Mountain Subsequence ...
随机推荐
- HDU 2089 简单数位dp
1.HDU 2089 不要62 简单数位dp 2.总结:看了题解才敲出来的,还是好弱.. #include<iostream> #include<cstring> #i ...
- C#实现动态页面静态化
制作一个aspx页面,专门用来生成各个动态aspx页面的静态页面.如下图所示,仅将内容页和主页面生成静态页面,当然本例只是一个简单的范例,实际情况如很复杂,但原理都是相同的. 生成内容页: 本例中的不 ...
- Ajax注册验证js代码
分享jquery网站:http://www.css88.com/jqapi-1.9/focusout/ $(document).ready(function() { var bool_user = f ...
- .net的五层架构
原文章地址是http://www.360doc.com/content/11/1210/21/19147_171335782.shtml 我们刚开始学习架构的时候,首先会想到分层的概念,分层架构比较经 ...
- spring mvc 拦截器 拦截子目录
项目中碰到这一个问题: 对于/user/loginpage,/user/login这一类的url,放行: 对于/user/{userId}/xxx(xxx不为空)的操作,需要拦截,url-patter ...
- LaTex Font Size 字体大小命令
LaTex中字体大小有很多中等级,分别由下列命令控制: \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE ...
- jquery实现获取手机验证码倒计时效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 使用ftp软件上传下载php文件时换行丢失bug
正 文: 在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下notepad++编辑器写好的php文件,在使用ftp上传到linux服务器后,php文件的换行符全部丢失了, ...
- ZK dropEvent简单使用
前台(Drop.zul) <?page title="拖动测试" contentType="text/html;charset=UTF-8"?> & ...
- PHP版本过狗Shell
默认密码demo使用方法 按p 输入密码 或者 你保存的xx.php?password=demo自定义密码在define('iphp','demo2'); demo2 为你设定的密码. <?ph ...