We are given a pointer P that points to a three-level memory structure. The first level is an array of pointers which ends with a NULL, and each of the non-null pointers in the array points to a pointer variable in the second level. Then each of these second level pointers point to an integer in the third level.
Now, you need to traverse the first level array, and go to the integers in the third level through the pointers, and you need to count the number of first level pointers that can reach the same integers.
Let us illustrate this task with two examples. In the first example, we assume that all pointers point to different locations, i.e., all mappings are one-to-one. Please refer to the following figure. As a result each integer in the third level can be access by exactly one pointer from the first level.
figure
In the second example, we assume that some pointers may point to the same locations, i.e. the mapping is many-to-one. Please refer to the following figure.
figure
1 <= Max number of non-null pointers in the first level <= 512
1 <= Max number of pointers in second level <= 512
1 <= Max number of integer variables in third level <= 512
Output Format
Print the integers and the number of first level pointers that can reach them. You must print the integers in increasing order of the numbers of the first level pointers that can reach them. If two integers have the same numbers of the first level pointers that can reach them, print the smaller integer first.
Task Description
We are given a pointer P that points to a three-level memory structure. The first level is an array of pointers which ends with a NULL, and each of the non-null pointers in the array points to a pointer variable in the second level. Then each of these second level pointers point to an integer in the third level.
Now, you need to traverse the first level array, and go to the integers in the third level through the pointers, and you need to count the number of first level pointers that can reach the same integers.
Let us illustrate this task with two examples. In the first example, we assume that all pointers point to different locations, i.e., all mappings are one-to-one. Please refer to the following figure. As a result each integer in the third level can be access by exactly one pointer from the first level. figure
In the second example, we assume that some pointers may point to the same locations, i.e. the mapping is many-to-one. Please refer to the following figure. figure
The prototype of count function is as follows.
The count.h is as follow:
You may use the following main function to test your function.
Main Function 1
Main Function 2
Subtask
Input Format
1 <= Max number of non-null pointers in the first level <= 512 1 <= Max number of pointers in second level <= 512 1 <= Max number of integer variables in third level <= 512
Output Format
Print the integers and the number of first level pointers that can reach them. You must print the integers in increasing order of the numbers of the first level pointers that can reach them. If two integers have the same numbers of the first level pointers that can reach them, print the smaller integer first.
Notes
You need to print the answers in you function.
Sample Output 1
Sample Output 2