#C2423. Total File Size in Directory
Total File Size in Directory
Total File Size in Directory
You are given a list of files with their respective sizes and a target directory. Your task is to compute the total size occupied by the files located in the target directory as well as any of its subdirectories.
More formally, you are given an integer \(N\) representing the number of files. Then, \(N\) lines follow. Each line contains a file path and an integer representing the file size. Finally, the last line contains a target directory. Calculate the sum of sizes for all files whose file path begins with the given target directory. Assume that file paths do not contain spaces and the target directory provided is valid.
Note: Use the prefix matching (i.e., the file path starts with the given directory string) to decide if a file belongs to the target directory.
inputFormat
The first line contains an integer (N), the number of files. The following (N) lines each contain a file path (a string without spaces) and a file size (an integer), separated by space. The last line contains the target directory as a string.
outputFormat
Output a single integer representing the total file size in the target directory including all its subdirectories.## sample
6
/home/user/document.txt 120
/home/user/notes/todo.txt 80
/home/user/pictures/photo.jpg 240
/home/user/pictures/photo2.jpg 340
/home/user/notes/research.pdf 100
/home/user/readme.md 20
/
900