← 返回 anthropic 的题目列表Find Duplicate Files by Content
类型:online_judge
Problem: Find Duplicate Files by Content
You are given several directory description lines. Each line describes a directory and the files directly under it, using the following format:
<directory_path> <file_name_1>(<content_1>) <file_name_2>(<content_2>) ...
Where:
<directory_path> is the directory path;
each file is represented as filename(content);
tokens are separated by spaces;
file content does not contain the character ).
Find all files that have exactly the same content and output their full paths grouped together.
Only groups containing at least two files should be output. Files with unique content should not be output.
Input Format
n
line_1
line_2
...
line_n
The first line contains an integer n, the number of directory description lines.
The next n lines contain directory descriptions.
Output Format
Print one line per duplicate group. Paths in the same group should be separated by one space.
To make the output deterministic:
Sort paths inside each group lexicographically.
Sort all groups by the first path in each group.
If there are no duplicate files, print nothing.
Constraints
1 <= n <= 10^4
Total number of files <= 10^5
Each path, filename, and content length is at most 10^4
Total input size fits in memory.
Example
Input:
4
root/a 1.txt(abcd) 2.txt(efgh)
root/c 3.txt(abcd)
root/c/d 4.txt(efgh)
root 4.txt(efgh)
Output:
root/4.txt root/a/2.txt root/c/d/4.txt
root/a/1.txt root/c/3.txt
Example
Input
4
root/a 1.txt(abcd) 2.txt(efgh)
root/c 3.txt(abcd)
root/c/d 4.txt(efgh)
root 4.txt(efgh)
Output
root/4.txt root/a/2.txt root/c/d/4.txt
root/a/1.txt root/c/3.txt