22653_DiskTree

2022-5-16 18:22| 发布者: Hocassian| 查看: 24| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506824150799-Problem List-采集的数据-后羿采集器.html

Pro.ID

22653

Title

Disk Tree

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22653

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Hacker Bill has accidentally lost all the information from his workstation's hard drive and he has no backup copies of its contents. He does not regret for the loss of the files themselves, but for the very nice and convenient directory structure that he had created and cherished during years of work. Fortunately, Bill has several copies of directory listings from his hard drive. Using those listings he was able to recover full paths (like "WINNT\SYSTEM32\CERTSRV\CERTCO~1\X86") for some directories. He put all of them in a file by writing each path he has found on a separate line. Your task is to write a program that will help Bill to restore his state of the art directory structure by providing nicely formatted directory tree.

    输入

    The first line of the input file contains single integer number N ( 1 ≤ N ≤ 500 ) that denotes a total number of distinct directory paths. Then N lines with directory paths follow. Each directory path occupies a single line and does not contain any spaces, including leading or trailing ones. No path exceeds 80 characters. Each path is listed once and consists of a number of directory names separated by a back slash ("\").

    Each directory name consists of 1 to 8 uppercase letters, numbers, or the special characters from the following list: exclamation mark, number sign, dollar sign, percent sign, ampersand, apostrophe, opening and closing parenthesis, hyphen sign, commercial at, circumflex accent, underscore, grave accent, opening and closing curly bracket, and tilde ("!#$%&'()-@^_`{}~").

    输出

    Description

    Hacker Bill has accidentally lost all the information from his workstation's hard drive and he has no backup copies of its contents. He does not regret for the loss of the files themselves, but for the very nice and convenient directory structure that he had created and cherished during years of work. Fortunately, Bill has several copies of directory listings from his hard drive. Using those listings he was able to recover full paths (like "WINNT\SYSTEM32\CERTSRV\CERTCO~1\X86") for some directories. He put all of them in a file by writing each path he has found on a separate line. Your task is to write a program that will help Bill to restore his state of the art directory structure by providing nicely formatted directory tree.

    Input

    The first line of the input file contains single integer number N ( 1 ≤ N ≤ 500 ) that denotes a total number of distinct directory paths. Then N lines with directory paths follow. Each directory path occupies a single line and does not contain any spaces, including leading or trailing ones. No path exceeds 80 characters. Each path is listed once and consists of a number of directory names separated by a back slash ("\").

    Each directory name consists of 1 to 8 uppercase letters, numbers, or the special characters from the following list: exclamation mark, number sign, dollar sign, percent sign, ampersand, apostrophe, opening and closing parenthesis, hyphen sign, commercial at, circumflex accent, underscore, grave accent, opening and closing curly bracket, and tilde ("!#$%&'()-@^_`{}~").

    Output

    Write to the output file the formatted directory tree. Each directory name shall be listed on its own line preceded by a number of spaces that indicate its depth in the directory hierarchy. The subdirectories shall be listed in lexicographic order immediately after their parent directories preceded by one more space than their parent directory. Top level directories shall have no spaces printed before their names and shall be listed in lexicographic order. See sample below for clarification of the output format.

    Sample Input
    7
    WINNT\SYSTEM32\CONFIG
    GAMES
    WINNT\DRIVERS
    HOME
    WIN\SOFT
    GAMES\DRIVERS
    WINNT\SYSTEM32\CERTSRV\CERTCO~1\X86
    Sample Output
    GAMES
    DRIVERS
    HOME
    WIN
    SOFT
    WINNT
    DRIVERS
    SYSTEM32
     CERTSRV
      CERTCO~1
    X86
     CONFIG
    Source

    样例输入

    7
    WINNT\SYSTEM32\CONFIG
    GAMES
    WINNT\DRIVERS
    HOME
    WIN\SOFT
    GAMES\DRIVERS
    WINNT\SYSTEM32\CERTSRV\CERTCO~1\X86

    样例输出

    GAMES
    DRIVERS
    HOME
    WIN
    SOFT
    WINNT
    DRIVERS
    SYSTEM32
     CERTSRV
      CERTCO~1
    X86
     CONFIG

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部