题意:

  输出每个单词的缩写  使得每个单词 互不相同。。

解析:

   统计每个前出现的次数。。。然后在查询的时候  遇到次数为1的返回即可。。

  

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int trie[maxn][], sum[maxn];
int rt, tot;
char str[maxn][];
vector<char> v;
void build(char *s)
{
int len = strlen(s);
rt = ;
for(int i=; i<len; i++)
{
int x = s[i] - 'a';
if(trie[rt][x] == ) trie[rt][x] = ++tot;
rt = trie[rt][x];
sum[rt]++;
}
} void qp(char *s)
{
int len = strlen(s);
rt = ;
for(int i=; i<len; i++)
{
v.push_back(s[i]);
int x = s[i] - 'a';
if(trie[rt][x] == ) return;
rt = trie[rt][x];
if(sum[rt] == ) return;
}
} int main()
{
int cnt = ;
while(cin>> str[++cnt])
{
build(str[cnt]);
}
rap(i, , cnt)
{
v.clear();
qp(str[i]);
cout<< str[i] << " ";
for(int i=; i<v.size(); i++)
cout<<v[i];
cout<<endl;
} return ;
}

Shortest Prefixes POJ - 2001(统计次数)的更多相关文章

  1. OpenJudge/Poj 2001 Shortest Prefixes

    1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...

  2. POJ 2001 Shortest Prefixes (Trie)

    题目链接:POJ 2001 Description A prefix of a string is a substring starting at the beginning of the given ...

  3. POJ 2001 Shortest Prefixes(字典树活用)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21651   Accepted: 927 ...

  4. poj 2001:Shortest Prefixes(字典树,经典题,求最短唯一前缀)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12731   Accepted: 544 ...

  5. POJ 2001:Shortest Prefixes

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16782   Accepted: 728 ...

  6. poj 2001 Shortest Prefixes trie入门

    Shortest Prefixes 题意:输入不超过1000个字符串,每个字符串为小写字母,长度不超过20:之后输出每个字符串可以简写的最短前缀串: Sample Input carbohydrate ...

  7. POJ 2001 Shortest Prefixes(字典树)

    题目地址:POJ 2001 考察的字典树,利用的是建树时将每个点仅仅要走过就累加.最后从根节点開始遍历,当遍历到仅仅有1次走过的时候,就说明这个地方是最短的独立前缀.然后记录下长度,输出就可以. 代码 ...

  8. POJ 2001 Shortest Prefixes 【 trie树(别名字典树)】

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15574   Accepted: 671 ...

  9. poj 2001 Shortest Prefixes(字典树trie 动态分配内存)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15610   Accepted: 673 ...

随机推荐

  1. day 3 模块

    1.系统自带模块  xxx.py 文件 就是模块 ### 模块存放位置 In [1]: import os In [2]: os.__file__ Out[2]: '/usr/lib/python3. ...

  2. unity图形圆形展开

    脚本如下: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngi ...

  3. python数据可视化——matplotlib 用户手册入门:pyplot 画图

    参考matplotlib官方指南: https://matplotlib.org/tutorials/introductory/pyplot.html#sphx-glr-tutorials-intro ...

  4. C#匿名参数(转载too)

    匿名方法是在初始化委托时内联声明的方法. 例如下面这两个例子: 不使用匿名方法的委托: using System; using System.Collections.Generic; using Sy ...

  5. HP Vitrual Connect 配置快速参考

    使用任意浏览器,在地址栏输入VC的管理地址(如果不知道VC的管理地址请从OA中进入) 输入用户名和密码登入VC,验证成功后将进入VM的配置向导 点击"Next"继续,将先进行Dom ...

  6. java使用jacob将office文档转换为PDF格式

    jacob 包下载地址: http://sourceforge.net/projects/jacob-project/ 下载后,将jacob 与 jacob-1.19-x64.dll放到安装jdk目录 ...

  7. tcp三次握手 四次挥手 (转)

    转自: http://blog.csdn.net/whuslei/article/details/6667471 建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看 ...

  8. lambda(匿名函数)---基于python

    在学习python的过程中,lambda的语法时常会使人感到困惑,lambda是什么,为什么要使用lambda,是不是必须使用lambda? 下面就上面的问题进行一下解答. 1.lambda是什么? ...

  9. ie6下,莫名被复制出一段文字解决

    在IE6下使用浮动可能会出现文字重复的情况. 在IE6下,浮动层之间有注释文字的话,之前那个浮动层的内容文字就有可能遭遇一个“隐形”的复制,但是代码里查看文字可并没有多出来. 看个例子: HTML & ...

  10. QT中文乱码解决方法

    由于我毕设的界面是用Qt做的,之前没怎么接触过Qt,所以实现过程中遇到不少小问题,头一个就是这个. 现如今宝宝将其记录下来,供同样有需要的同学或者自己以后方便查阅. 1.所有文件编码格式须一致 不统一 ...