【Phone List 1671 Trie】
来源:互联网 发布:阿里云服务器磁盘挂载 编辑:程序博客网 时间:2024/06/07 22:26
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct TrieNode{ int count; struct TrieNode *next[10];};struct TrieNode *root;void Init(){ root=new TrieNode; root->count=0; for(int i=0;i<10;i++) root->next[i]=NULL;}void Insert(char *s){ TrieNode *head=root; int len=strlen(s); for(int i=0;i<len;i++){ if(head->next[s[i]-'0']==NULL){ head->next[s[i]-'0']=new TrieNode; head=head->next[s[i]-'0']; for(int i=0;i<10;i++) head->next[i]=NULL; head->count=1; } else{ head=head->next[s[i]-'0']; head->count++; } }}int search(char *s){ TrieNode *head=root; int len=strlen(s); for(int i=0;i<len;i++){ head=head->next[s[i]-'0']; } return head->count;}void Del(TrieNode *head){ for(int i=0;i<10;i++) if(head->next[i]!=NULL) Del(head->next[i]); free(head);}int main(){ int t,n,i; char str[10001][20]; scanf("%d",&t); while(t--){ Init(); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%s",str[i]); Insert(str[i]); } int flag=0; for(int i=0;i<n;i++){ if(search(str[i])!=1){ flag=0; break; } flag=1; } if(flag) printf("YES\n"); else printf("NO\n"); Del(root); }}
- 【Phone List 1671 Trie】
- hdu 1671 Phone List(trie)
- HDU 1671 Phone List(Trie)
- hdu 1671 Phone List (Trie树,水题)
- hdu 1671 Phone List trie树
- 1671 Phone List (Trie树)
- HDU 1671 Phone List(字典树Trie)
- hdu 1671 Phone List(数据结构:trie)
- HDU 1671 Phone List Trie树
- Phone List - HDU 1671 Trie树
- HDU 1671 Phone List(字典树Trie)
- HDOJ-1671Phone List(Trie树)
- hdu-1671-Phone List Trie树
- HDU 1671 Phone List (Trie)
- hdu 1671 Phone List(Trie树)
- HDU 1671 Phone List trie树
- HDOJ-1671 Phone List(Trie树)
- hdu 1671 Phone List Trie树
- 陶渊明《闲情赋并序》原文与译文
- 驱动程序学习(一)从“hello world”开始
- 用指针将一个字符串a复制到字符串b并且输出字符串b
- 点的计算
- HDU 1010 Tempter of the Bone (ZOJ 2110) DFS+剪枝
- 【Phone List 1671 Trie】
- Deep Learning:Sparse Coding ScSPM & LLC
- 带鼠标的屏幕截图
- 每天一个linux命令(21):find命令之xargs
- ios获取安装应用程序列表
- 每天一个linux命令(22):find 命令的参数详解
- HOOK SSDT禁用内存写保护
- 每天一个linux命令(23):Linux 目录结构
- boa-0.94.13 Web服务器的编译与运行