Phone Number
来源:互联网 发布:淘宝网人气女模特 编辑:程序博客网 时间:2024/05/21 11:23
Description
We know that if a phone number A is another phone number B’s prefix, B is not able to be called. For an example, A is 123 while B is 12345, after pressing 123, we call A, and not able to call B. Given N phone numbers, your task is to find whether there exits two numbers A and B that A is B’s prefix.
Input
The input consists of several test cases. 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.
Output
For each test case, if there exits a phone number that cannot be called, print “NO”, otherwise print “YES” instead.
Sample Input
20120123452120123450
Sample Output
NOYES
//关键字:字典树
//标程:
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>using namespace std;typedef struct Node{ Node *child[10]; int n;}Node;int flag;void Insert(Node *root,char *str){ int len=strlen(str); Node *ans=root; for (int i=0;i<len;i++) { if(ans->child[str[i]-'0']== NULL) { Node *NewNode = (Node*) malloc (sizeof (Node)); NewNode->n =1; for(int j=0;j<10;j++) NewNode->child[j]=NULL; ans->child[str[i]-'0'] = NewNode; ans = NewNode; } else { ans = ans->child[str[i]-'0']; ans->n++; if(ans->n>1) flag=1; } }}int main(){ //freopen("a.txt","r",stdin); char s[1010]; int n; while(scanf("%d\n",&n),n) { flag=0; Node *root=(Node*)malloc (sizeof (Node)); root->n = 0; int i; for (i = 0; i < 10; i++) root->child[i] = NULL; for(i=0;i<n;i++) { gets(s); Insert(root,s); } if(!flag) printf("YES\n"); else printf("NO\n"); } return 0;}
- Phone Number
- Phone Number
- Phone Number
- Encoded Phone Number help
- Ural 1002 Phone number
- oz phone number regex
- sdut2151 Phone Number
- Phone Number Divide
- Read Phone Number
- Read Phone Number
- Read Phone Number
- SDUT 2151 - Phone Number
- 第一届省赛 Phone Number
- Phone number - Multiway Trees
- [数据结构]Phone-Number Manager
- Read Phone Number
- Create Phone Number
- 17 phone number
- Spring mvc 转发、重定向
- NYOJ 62 笨小熊
- 软件工程实验二
- scanf函数的特点
- 我的android 第28天 - Activity(一)
- Phone Number
- Cocos2D 开发工具集
- Extjs4 combobox静态本地数据实现省市联动
- svchost.exe进程的分析
- 基于C#弹幕类射击游戏的实现——(四)玩家的战机
- android widget的中文文档
- Greatest Number
- Linux文件系统恢复
- 做嵌入式驱动的前途何在