题目连接: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(特里)的更多相关文章

  1. ural1067 Disk Tree

    Disk Tree Time limit: 2.0 secondMemory limit: 64 MB Hacker Bill has accidentally lost all the inform ...

  2. POJ 题目1145/UVA题目112 Tree Summing(二叉树遍历)

    Tree Summing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8132   Accepted: 1949 Desc ...

  3. UVA 11922 Splay tree

    UVA 11922 题意: 有n个数1~n 操作a,b表示取出第a~b个数,翻转后添加到数列的尾部 输入n,m 输入m条指令a,b 输出最终的序列 代码: #include<iostream&g ...

  4. HDU 1504 Disk Tree

    转载请注明出处:http://blog.csdn.net/a1dark 分析:查了一下这题.发现网上没有什么关于这道题的解题报告.其实题目意思挺好懂的.就是给你一些文件的目录结构.然后让你把它们组合在 ...

  5. 1067. Disk Tree(字符串)

    1067 破题啊  写完发现理解错题意了 子目录下会有跟之前重名的 把输入的字符串存下来 排下序 然后依次找跟上面有没有重的 #include <iostream> #include< ...

  6. 【HDOJ】1504 Disk Tree

    文件可以重名.先按字典序将路径排序,再过滤掉公共前缀.其中的问题是'\'的ASCII比[A-Z0-9]大,将它替换为空格.否则字典序有问题. /* 1504 */ #include <iostr ...

  7. 【UVA】536 Tree Recovery(树型结构基础)

    题目 题目     分析 莫名A了     代码 #include <bits/stdc++.h> using namespace std; string s1,s2; void buil ...

  8. uva 6910 - Cutting Tree 并查集的删边操作,逆序

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  9. 【习题 6-11 UVA - 10410】Tree Reconstruction

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以先确定当前这棵子树的dfs序的范围. 然后第一个元素肯定是这棵子树的根节点. 那么只要在这棵子树的范围里面枚举节点. 看看有没有 ...

随机推荐

  1. [WebView五学习]:调试Web Apps

    上一篇我们学习了([WebView学习之四]:迁移到Android4.4版本号的WebView),今天我们来继续学习. (博客地址:http://blog.csdn.net/developer_jia ...

  2. oracle 关于日期格式转换与使用

    在oracle中我们经常会和日期打交道,在做报表的时候经常会用日报,周报,月报之类的条件进行分组: 我写了些例子来启发下大脑 select Sysdate from dual select to_ch ...

  3. Codeforces Round #256 (Div. 2) A. Rewards

    A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  4. [置顶] ios 一个不错的图片浏览分享框架demo

    demo功能:一个不错的图片浏览分享框架demo.iphone6.1 测试通过.可以浏览图片,保存,微博分享到新浪,腾讯,网易,人人等. 注:(由于各个微博的接口有时候会有调整,不一定能分享成功.只看 ...

  5. Sliverlight之 画刷

    1,5种画刷 (见Project15) (1)TextBlock控件中的Forground和BackGround属性是一个什么对象?它在前台的完整的写法是什么?(实际是.net做了一个转换,可以直接写 ...

  6. 修改字符串中特定的内容,用于OpenRecovery Script

    下面的是实例内容 目标是把OpenRecovery Script输入的内容进行修改 当有下面的输入:(作用是安装/emmc目录下面的update-signed.zip 刷机包) install /em ...

  7. Android自己主动化測试——CTS測试

    一.为什么须要兼容性測试(下面称CTS)? 1.1.让APP提供更好的用户体验.用户能够选择很多其它的适合自己设备的APP.让APP更稳定. 1.2.让开发人员设计更高质量的APP. 1.3.通过CT ...

  8. Linux 编程学习笔记----过程管理和项目发展(在)

    转载请注明出处,http://blog.csdn.net/suool/article/details/38406211,谢谢. Linux进程存储结构和进程结构 可运行文件结构 例如以下图: 能够看出 ...

  9. QT 打开文件对话框汇总

    Qstring fileName = QFileDialog::getOpenFileName(this, tr("open file"), " ",  tr( ...

  10. 我学的是设计模式的视频教程——命令模式vs策略模式,唠嗑

    课程视频 命令模式vs策略模式 唠嗑 课程笔记 课程笔记 课程代码 课程代码 新课程火热报名中 课程介绍 版权声明:本文博主原创文章,博客,未经同意不得转载.