Hard
Files and Folders
Write
class Item with a name and a size() method, File(name, size) and Folder(name) that holds items and whose size is the total of its contents. Read lines path size (like docs/notes.txt 120) until END, building folders as needed under a root called root. Print the tree: each item on its own line indented 2 spaces per level as name (size), folders before files, each group alphabetical.Input
Lines, then END.
Output
Lines.
Sample 1
Input
docs/notes.txt 120 docs/cv.pdf 300 photo.jpg 500 docs/old/a.txt 5 END
Output
root (925)
docs (425)
old (5)
a.txt (5)
cv.pdf (300)
notes.txt (120)
photo.jpg (500)Sample 2
Input
x.txt 1 END
Output
root (1) x.txt (1)
Output appears here