uva 1556 - Disk Tree(特里)
题目大意:给出N个文件夹关系,然后依照字典序输出整个文件文件夹。
解题思路:以每一个文件夹名作为字符建立一个字典树就可以,每一个节点的关系能够用map优化。
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 50005;
typedef map<string, int>::iterator iter;
struct Tire {
int sz;
map<string, int> g[maxn];
void init();
void insert(string s);
void put(int u, int d);
}tree;
int main () {
int n;
string s;
while (cin >> n && n) {
tree.init();
for (int i = 0; i < n; i++) {
cin >> s;
s += '\\';
tree.insert(s);
}
tree.put(0, 0);
cout << endl;
}
return 0;
}
void Tire::init() {
sz = 1;
g[0].clear();
}
void Tire::insert(string s) {
int u = 0;
string word = "";
for (int i = 0; i < s.length(); i++) {
if (s[i] == '\\') {
if (!g[u].count(word)) {
g[sz].clear();
g[u][word] = sz++;
}
u = g[u][word];
word = "";
} else
word += s[i];
}
}
void Tire::put (int u, int d) {
for (iter i = g[u].begin(); i != g[u].end(); i++) {
for (int j = 0; j < d; j++)
cout << " ";
cout << i->first << endl;
put(i->second, d + 1);
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
uva 1556 - Disk Tree(特里)的更多相关文章
- ural1067 Disk Tree
Disk Tree Time limit: 2.0 secondMemory limit: 64 MB Hacker Bill has accidentally lost all the inform ...
- POJ 题目1145/UVA题目112 Tree Summing(二叉树遍历)
Tree Summing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8132 Accepted: 1949 Desc ...
- UVA 11922 Splay tree
UVA 11922 题意: 有n个数1~n 操作a,b表示取出第a~b个数,翻转后添加到数列的尾部 输入n,m 输入m条指令a,b 输出最终的序列 代码: #include<iostream&g ...
- HDU 1504 Disk Tree
转载请注明出处:http://blog.csdn.net/a1dark 分析:查了一下这题.发现网上没有什么关于这道题的解题报告.其实题目意思挺好懂的.就是给你一些文件的目录结构.然后让你把它们组合在 ...
- 1067. Disk Tree(字符串)
1067 破题啊 写完发现理解错题意了 子目录下会有跟之前重名的 把输入的字符串存下来 排下序 然后依次找跟上面有没有重的 #include <iostream> #include< ...
- 【HDOJ】1504 Disk Tree
文件可以重名.先按字典序将路径排序,再过滤掉公共前缀.其中的问题是'\'的ASCII比[A-Z0-9]大,将它替换为空格.否则字典序有问题. /* 1504 */ #include <iostr ...
- 【UVA】536 Tree Recovery(树型结构基础)
题目 题目 分析 莫名A了 代码 #include <bits/stdc++.h> using namespace std; string s1,s2; void buil ...
- uva 6910 - Cutting Tree 并查集的删边操作,逆序
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【习题 6-11 UVA - 10410】Tree Reconstruction
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以先确定当前这棵子树的dfs序的范围. 然后第一个元素肯定是这棵子树的根节点. 那么只要在这棵子树的范围里面枚举节点. 看看有没有 ...
随机推荐
- php编码规范个人小结
1.原生态代码或者类的头上,注明作者,关键算法计算过程 例如 /** *@author zengmoumou *功能:根据列表ip,取得ip对应的运营商,省,市,县 */ 2.变量尽量用英文单词的组合 ...
- 手动安装英特尔® 凌动™ Android* x86 模拟器映像
android的模拟器实在是太慢了,慢的让人欲仙欲死,欲罢不能.猛然发现我的电脑是intel的CPU,我勒个去,换x86模拟器.然后悲剧了,伟大的gfw 我要装sdk,我要研究android开发,到底 ...
- poj3928 Ping pong 树状数组
http://poj.org/problem?id=3928 Ping pong Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- [LeetCode290]Word Pattern
题目: Given a pattern and a string str, find if str follows the same pattern. Here follow means a full ...
- 产品CEO?别傻了,你不是拿破仑
编者按:本文出自技术产品经理Daniel Elizalde的博客,中文版由天地会珠海分舵进行编译. 全文针对如今流行的把产品经理比喻成"产品CEO"的这一说法进行深入的分析.跟大家 ...
- Mongodb安装和配置
Mongodb之安装配置 安装 Mongodb的下载地址为Mongodb官网.下载时.你能够选择是安装包或者是压缩包. 下载完毕后.双击安装包并安装. 安装完毕后.你能够在安装文件夹看到下图中所见的文 ...
- OCP-1Z0-051-名称解析-文章12称号
12. You need to produce a report where each customer's credit limit has been incremented by $1000. I ...
- Android于JNI调用列出的程序
1.安装和下载cygwin,下载Android NDK: 2.于ndk工程JNI接口设计: 3.采用C/C++实现本地方法. 4.JNI生成动态链接库.so档: 5.动态链接库副本javaprojec ...
- Socket tips: UDP Echo service - Client code
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/soc ...
- Atitit.web三编程模型 Web Page Web Forms 和 MVC
Atitit.web三编程模型 Web Page Web Forms 和 MVC 1. 编程模型是 Web Forms 和 MVC (Model, View, Controller). 2. W ...