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 ...
随机推荐
- LINQ to Entities 和LINQ to Objects 的区别
本文资料来源:http://www.codeproject.com/Articles/246861/LINQ-to-Entities-Basic-Concepts-and-Features) LINQ ...
- CF 706B 简单二分,水
1.CF 706B Interesting drink 2.链接:http://codeforces.com/problemset/problem/706/B 3.总结:二分 题意:给出n个数,再给 ...
- 7zip ubuntu使用
http://www.cnblogs.com/yiwd/p/3649094.html 安装: sudo apt-get install p7zip 解压: 7zr x file -r -o./path ...
- 如何让代码实现C++
其实本来就知道 但是主要突然忘了去怎样实现C++代码 ,所以写个笔记记忆一下 让代码实现C++ 只需要修改.m文件为 .mm 就可以了 突然是不是很像打脸. 不过希望能给不知道的小伙伴一点帮助哦 ...
- 纪念逝去的岁月——C/C++排序二叉树
1.代码 2.运行结果 3.分析 1.代码 #include <stdio.h> #include <stdlib.h> typedef struct _Node { int ...
- JSch - Java实现的SFTP(文件下载详解篇)
上一篇讲述了使用JSch实现文件上传的功能,这一篇主要讲述一下JSch实现文件下载的功能.并介绍一些SFTP的辅助方法,如cd,ls等. 同样,JSch的文件下载也支持三种传输模式:OVERWRITE ...
- C# async
I/O should use async, asynchronous method can be achieved: message, delegate, multi-threading Thread ...
- JavaScript_Math函数
JavaScript_Math函数与属性按功能分类 Math三角函数与属性 Math.sin() -- 返回数字的正弦值 Math.cos() -- 返回数字的余弦值 Math.tan() -- 返回 ...
- windows查看进程
由端口到进程: 直接查看进程: 查看本机连接端口: 杀进程: (eg:kill httpd) tskill 1596
- HTML5标签简化写法
基本页面格式 <!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title ...