我怎样才能找到“最不常见的部分”?在同一逻辑驱动器上的路径之间?
我的节目有几个路径可以观看,比如
C:\XML
C:\MyProg\Raw
C:\MyProg\Subset\MTSAT
C:\MyProg\Subset\GOESW
D:\数据集\复合
D:\数据集\全局
E:\Dataset\Mosaic
我想向我的 CFolderWatch 类实例添加 4 个路径,即 C:\XML、C:\MyProg、D:\Dataset 和 E:\Dataset,以便监视 insetad 的文件夹只要其“包含子目录”开关设置为 TRUE,即可使用上述所有 7 个路径。假设所有被监视的路径都已添加到向量容器中。
因此,我的问题是:如何在同一逻辑驱动器上的路径中找到“最不常见的部分”?先感谢您!
我的问题的详细解释: 1.我得到了一些用户定义的目录。 2.我想要这些目录被观看。 3. 在观看之前,我想做一些准备工作,例如,找到同一逻辑驱动器上的路径之间的公共部分,以避免可能向我的观看类添加太多路径。例如,逻辑盘C:上有3条路径,如下: C:\test\Data\R1、C:\test\Data\R2、C:\test\Data\R3,常用路径为“C:\test\Data”。因此,我们应该将“C:\test\Data”添加到监视模块中,而不是这三个路径。我的意思是这里的公共路径是它至少有一层目录。如果一条路径与其他路径没有共同路径,则仅返回不变。 4. 首先,算法应该处理不同的逻辑驱动器。也就是说,所有路径都必须根据各自的驱动器号进行分类。然后,在同一逻辑盘符上的传递路径中找到公共路径。
My program has several paths to be watched, such as
C:\XML
C:\MyProg\Raw
C:\MyProg\Subset\MTSAT
C:\MyProg\Subset\GOESW
D:\Dataset\Composite
D:\Dataset\Global
E:\Dataset\Mosaic
I want to add 4 paths, namely C:\XML, C:\MyProg, D:\Dataset and E:\Dataset, to my CFolderWatch class instance for the purpose of folder watching insetad of all 7 above-mentioned paths as long as its "Include Subdirectory" switch is set to TRUE. Suppose all paths of being watched have been added to a vector container.
Therefore, my question is: How can I find the "least common part" among the paths on the same logical drive? Thank you in advance!
Detailed explanation to my question:
1. I got some user-defined directories.
2. I want to these directories to be watched.
3. Before watching, I want to do some preparatory job, for example, find the common part among the path(s) on the same logical drive to avoid possibly adding so many paths to my watching class. For instance, if there are 3 paths on the logical drive C: as follows:
C:\test\Data\R1, C:\test\Data\R2, and C:\test\Data\R3, the common path is "C:\test\Data". So, we should add "C:\test\Data" to the watching module, not the three paths. What I mean the common path here is that it has at least one level of directory. If one path has no common path with the others, just returns unchanged.
4. First thing first, the algorithm should handle different logical drive(s). That is to say, all paths must be classified on the basis of their respective drive letter. Then, find the common path among the passed paths on the same logical drive letter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有算法;你使用了不一致的逻辑。
仅考虑集合
至少有 4 种不同的解决方案:
您无法解释为什么 2. 是正确的解决方案。可以编写一个算法,在给定解 N 作为输入的情况下找到解 N-1,因此您可以通过三个步骤从输入 (4) 到 (1)。但我们不明白为什么我们应该停在(2)。
There's no algorithm; you're using inconsistent logic.
Consider just the set
There are at least 4 different solutions:
You fail to explain why 2. is the correct solution. It is possible to write an algorithm that finds solution N-1 given solution N as input, so you can get from the input (4) to (1) in three steps. But we don't understand why we should stop at (2).
两步算法:
通过计算每个目录与其下一个同级目录共有的前缀字符数并保持最小值,可以轻松获得每个分区的最长前缀。例如,使用 mismatch。
A two-step algorithm:
The longest prefix per partition can be easily obtained by counting how many prefix characters each directory has in common with its next sibling, and keeping the minimum. Using mismatch, for example.
正如 JB 所说,我认为这是一个两步解决方案,我已经在 C# 中尝试了一些基本编码。如果你想在java中使用它,我想你一定知道如何使用它:)
这是一个非常简单的程序,假设你的路径在字符串中并检查重复项。如果路径数量较多,则必须采用更有效的解决方案。
As JB said I think this is a two step solution and I have tried some basic coding here in C#. If you want it in java I suppose you must be knowing how to use it :)
This is a very simple program that assumes that you have your paths in a string and checking for duplicates. If for a large no.of paths you must adopt a much more efficient solution.