poj 2001 Shortest Prefixes
来源:互联网 发布:mac版办公软件 编辑:程序博客网 时间:2024/06/07 21:55
还是字典树的基础题,纯粹为了熟练代码,加深理解
#include <set>#include <map>#include <ctime>#include <queue>#include <cmath>#include <stack>#include <limits>#include <vector>#include <bitset>#include <string>#include <cstdio>#include <cstring>#include <fstream>#include <string.h>#include <iostream>#include <algorithm>#define Si set<int>#define LL long long#define pb push_back#define PS printf(" ")#define Vi vector<int>#define LN printf("\n")#define lson l,m,rt << 1#define rson m + 1,r,rt<<1|1#define SD(a) scanf("%d",&(a))#define PD(a) printf("%d\n",a)#define SET(a,b) memset(a,b,sizeof(a))#define readf freopen("input.txt","r",stdin)#define writef freopen("output.txt","w",stdout)#define FF(i,a) for(int i(0);i<(a);i++)#define FD(i,a) for(int i(a);i>=(1);i--)#define FOR(i,a,b) for(int i(a);i<=(b);i++)#define FOD(i,a,b) for(int i(a);i>=(b);i--)const int maxn = 301;const int INF = ~0U>>1;const int dx[]={0,1,0,-1};const int dy[]={1,0,-1,0};const double pi = acos(-1.0);using namespace std;char a[1001][21];class tire{ public: int pre; tire *next[26]; tire(){ pre=0; SET(next,0); }}root;void insert(char *word){ tire *p=&root; int k=0; while(word[k]!='\0'){ if(!p->next[word[k]-'a']) p->next[word[k]-'a']=new tire; p=p->next[word[k]-'a']; p->pre++; k++; }}void query(char *word){ tire *p=&root; int k=0; while(word[k]){ if(p->pre==1) return; printf("%c",word[k]); int t=word[k]-'a'; p=p->next[t]; k++; }}int main(){ int cnt=0; while(~scanf("%s",a[cnt])){ insert(a[cnt]); cnt++; } FF(i,cnt){ printf("%s ",a[i]); query(a[i]); LN; } return 0;}
- POJ 2001 Shortest Prefixes
- poj 2001 Shortest Prefixes
- POJ 2001 Shortest Prefixes
- poj 2001 Shortest Prefixes
- poj 2001 Shortest Prefixes
- POJ 2001 Shortest Prefixes
- POJ-2001-Shortest Prefixes
- poj 2001 Shortest Prefixes
- POJ 2001 Shortest Prefixes
- POJ 2001 Shortest Prefixes
- poj 2001 Shortest Prefixes
- POJ-2001-Shortest Prefixes
- poj 2001 Shortest Prefixes
- POJ 2001 Shortest Prefixes
- poj 2001 Shortest Prefixes
- poj 2001 Shortest Prefixes
- POJ-2001 Shortest Prefixes
- POJ 2001 Shortest Prefixes
- iOS调试及发布
- CSS对<a>标签的操作
- 虚拟主机服务器php fsockopen函数被禁用的解决方法
- C++编程必备
- abstract class和interface有什么区别?
- poj 2001 Shortest Prefixes
- mysql 命令总结
- Sqlite3.78移植到VxWorks6.6
- 2012.6.6装箱、拆箱
- Facebook,C++库
- 苹果也是纸老虎,其nano-sim标准真是另人精艳
- c/c++资源(源码、开发工具、开发库)
- 最近wifi连接局域网出现问题
- 使用extjs动态load html页面时 ie出现错误 80020101