POJ_2001_Shortest Prefixes
题意:给定N个单词的字典,输出N个单词和这N个单词的确定字符串。
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<map> #include<cmath> using namespace std; struct Trie //字典树结构 {Trie *child[26];int num; //记录该字母的出现次数Trie() //构造函数 {num=0;memset(child,0,sizeof(child));} }; Trie *root,*s; void Create(char *str) //插入单词 {s=root;int i=0;while(str[i]){int id=str[i]-'a';if(s->child[id]==0) //如果该字母还没有出现在字典中 {s->child[id]=new Trie;s=s->child[id];}else{s=s->child[id];s->num++;}i++;} } void Search(char *str) {s=root;for(int i=0;i<strlen(str);++i){int id=str[i]-'a';s=s->child[id];printf("%c",str[i]);if(s->num==0) break; //如果该字母只出现了一次 }printf("\n"); } char a[1002][30]; int main() {int i=0,j;root=new Trie;while(~scanf("%s",a[i])){Create(a[i]);i++;}for(j=0;j<i;++j){printf("%s ",a[j]);Search(a[j]);}return 0; }
转载于:https://www.cnblogs.com/A-way/archive/2013/04/24/3040597.html
POJ_2001_Shortest Prefixes相关推荐
- OpenJudge/Poj 2001 Shortest Prefixes
1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...
- [poj 2001] Shortest Prefixes (字典树)
Language: Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20503 Accepte ...
- 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes kmp + dp
传送门 文章目录 题意: 思路: 题意: 思路: 通过完美子串的定义,我们不难发现满足条件的子串就是kmpkmpkmp中ne[n]ne[n]ne[n]不断向前跳得到的串,现在问题就是如何求这些前缀串在 ...
- 加强版[BZOJ#3483] SGU505 Prefixes and suffixes(询问在线版)
文章目录 description solution code #3483. SGU505 Prefixes and suffixes(询问在线版) description 给定
- 【POJ - 2001 】Shortest Prefixes (字典树,查询重复前缀区间)
题干: A prefix of a string is a substring starting at the beginning of the given string. The prefixes ...
- poj 2001 Shortest Prefixes(特里)
主题链接:http://poj.org/problem?id=2001 Description A prefix of a string is a substring starting at the ...
- Codeforces 432D Prefixes and Suffixes(KMP+dp)
题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出 ...
- B. Infinite Prefixes
链接:https://codeforces.com/contest/1295/problem/B You are given string ss of length nn consisting of ...
最新文章
- Python实现单链表
- Hive数据导入——数据存储在Hadoop分布式文件系统中,往Hive表里面导入数据只是简单的将数据移动到表所在的目录中!...
- Logger PatternLayout 格式
- 网易资深Java架构师:java数组对象转为list集合
- android代码打开数据库,android – 如何正确关闭并重新打开Room数据库
- tp5 的查询构造器
- 【SSM -MyBatis篇03】MyBatis Generator(MBG)配置属性详解(基于MyBatis3) - 逆向生成 - 配置MBG模板
- 【OpenCV + Python】时域和频域傅里叶变换
- redis创建集群,redis-trib.rb命令详解
- 投资理财启蒙之定投出一个千万富翁?
- Java学习:从入门到精通week3
- 360公司开源Atlas快速上手安装配置
- AI今年最大进展就是毫无进展?2019年AutoML、GAN将扛大旗
- 树莓派安装Windows
- jieba分词使用方法
- android usb gadget分析
- 从单机架构------》到现在复杂的微服务,分布式,集群,云平台途中是遇到了什么问题,又如何解决的?
- 什么是真正的需求,如何才能找到?
- XP Mod Android6,XP Mod Launcher仿XP桌面启动器的桌面软件
- 合并文件夹下多个PDF,PDF转图片,图片转PDF,JPG转pdf,pdf转JPG