[Full score] [HUAWEI OD machine test real questions 2023 JAVA&JS] file directory size

Huawei OD2023 (B volume) machine test question bank is fully covered, click here for the guide to brushing the questions

file directory size

Knowledge point recursion

Time limit: 1s Space limit: 256MB Limited language: unlimited

Title description:

The data format of a file directory is: directory id, file size in this directory, (subdirectory id list). Among them, the directory id is globally unique, the value range is [1,200], the file size range in this directory is [1,1000], and the number of subdirectory id lists is [0,10] For example:
1 20 (2,3) means files in directory 1 The total size is 20, and there are two subdirectories with ids 2 and 3

Now input all directory information in a file system and the directory id to be queried, and return the sum of the sizes of this directory and all subdirectories of this directory.

Enter a description:

The first line contains two numbers M and N, respectively representing the number of directories and the id of the directory to be queried, 1 <= M <=100, 1<= N <=200 and the next M lines, each line contains the data of one
directory : Directory id The size of files in this directory (list of subdirectory ids), the subdirectory ids in the subdirectory list are separated by commas.
 

Output description:

The size of the directory to be queried and its subdirectories

おすすめ

転載: blog.csdn.net/qq_34465338/article/details/131327150