1777: file structure "figure", 1777 file structure
1777: file structure "Graph"
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
It is usually useful to see the structure of a file system on a computer. The "explorer" program on Microsoft Windows is an example. However, there was no graphical representation before the graphic interface. At that time, the best way was to display the Directory and file structure as a "Graph, in addition, the structure of the directory is expressed in the form of contraction. For example:
ROOT
| dir1
| file1
| file2
| file3
| dir2
| dir3
| file1
file1
file2
This figure shows that the ROOT directory contains three subdirectories and two files. The first subdirectory contains three files, the second subdirectory is empty, and the third subdirectory contains one file.
-
Input
-
Your task is to write a program to read some test data. Each group of test data indicates the file structure of a computer. Each group of test data ends with '*', and all reasonable input data ends. A group of test data includes the names of some files and directories (although we did not give them in the input, we always assume that the ROOT directory is the outermost directory ). In the input, ']' indicates the end of a directory. The first letter of the directory name is 'D', and the first letter of the file name is 'F '. The file name may have no extension (such as fmyfile. dat and fmyfile ). The file and directory names do not contain spaces and the length cannot exceed 30. The sum of the number of subdirectories and the number of files in a directory cannot exceed 30.
-
Output
-
When displaying the content in a directory, first display the sub-directories (if any) and then display the files (if any ). Files must be displayed in the alphabetical order of their names (directories are not displayed in the alphabetical order of their names, but only in the order of their names ). For each group of test DATA, we must first output "data set x:". Here, x is the number of the test DATA (starting from 1 ). An empty row is output to separate the two groups of test data.
You need to note that we use a '|' and five spaces to indicate the level of the contraction.
-
Sample Input
-
file1file2dir3dir2file1file2]]file4dir1]file3*file2file1*#
-
Sample output
-
DATA SET 1:ROOT| dir3| | dir2| | file1| | file2| dir1file1file2file3file4DATA SET 2:ROOTfile1file2
-
Prompt
-
A directory and Its subdirectories are in different layers.
A directory is at the same level as the files in it.
-
Source
-
Translated from the question of Pacific Northwest 1998
1 # include <iostream> 2 # include <algorithm> 3 # include <cstdio> 4 using namespace std; 5 string a; 6 int cc; // output depth 7 int now = 1; // record current * quantity 8 int flag = 0; 9 void work () 10 {11 string str [50]; // store the file 12 int l = 0 in this directory; 13 while (cin> a) 14 {15 if (flag = 0 & a [0]! = '#') 16 {17 cout <"data set" <now <":" <endl; 18 cout <"ROOT" <endl; 19 flag = 1; 20} 21 if (a [0] = '#') 22 return; 23 else if (a [0] = '*') 24 {25 cc = 0; 26 sort (str + 0, str + l); 27 for (int I = 0; I <l; I ++) 28 {29 cout <str [I] <endl; 30} 31 cout <endl; 32 now ++; 33 // cout <"data set" <now <":" <endl; 34 // cout <"ROOT" <endl; 35 flag = 0; 36 work (); 37} 38 else if (a [0] = 'D') 39 {40 // cc ++; 41 // str [l] =; 42 // l ++; 43 cc ++; 44 for (int I = 1; I <= cc; I ++) 45 {46 cout <"| "; 47 for (int j = 1; j <= 5; j ++) 48 cout <"; 49} 50 cout <a <endl; 51 work (); 52} 53 else if (a [0] = 'F') 54 {55 56 str [l] = a; 57 l ++; 58 continue; 59} 60 else if (a [0] = ']') 61 {62 63 sort (str + 0, str + l); 64 for (int I = 0; I <l; I ++) 65 {66 for (int k = 1; k <= cc; k ++) 67 {68 cout <"| "; 69 for (int j = 1; j <= 5; j ++) 70 cout <"; 71} 72 cout <str [I] <endl; 73} 74 cc --; 75 return; 76} 77} 78} 79 int main () 80 {81 // freopen ("r.txt", "r", stdin ); 82 // freopen ("cmdtxt", "w", stdout); 83 work (); 84 return 0; 85}