Please review my code here in C... there are errors occurring and I'm not sure why. Input will begin with a line containing 1 integer, n (1 ≤ n ≤ 200,000), representing the number of exhibits in the park (including the entrance). The following line contains 2 integers, i and m (i = 1; 1 ≤ m ≤ 5,000), representing the ID of the entrance and the number of monkeys at the entrance. Each of the following 2n - 2 lines will contain a path description recorded by our employee. If this is the first time the employee used the path, then the line will contain two integers, i and m (2 ≤ i ≤ n; 1 ≤ m ≤ 5,000), representing the ID of the destination exhibit and the monkeys at the destination exhibit respectively. If this is the second time the path is used, then the line will contain the integer -1 instead, since the ID and number of monkeys were already recorded. You can assume that the monkeys don’t move between exhibits. Output should contain v lines. Each line will contain a corresponding integer representing the number of unique monkeys seen in the corresponding visitor’s park visit. The order of the output should correspond to the order of the input. Example: Sample input: 4 1 10 2 13 4 25 -1 3 6 -1 -1 3 4 3 2 Output: 48 29 23 Sample input: 5 1 1 2 2 3 3 -1 -1 4 4 5 5 -1 -1 2 3 5 Output: 6 10 Code is below: #include #include int sumofstack(int s[], int n); int main() { int n; scanf("%d", &n); int i=0, a,c, stack [n], p = 0 ; int dis[n]; while (i<( (2*n)-1)) { scanf("%d", &a); if ( a > 0 ) { scanf("%d", &c); stack[p]=c; dis[a=1]=sumofstack(stack,p); p++; else { p--; } i++; } scanf("%d", &n); for (int i = 0 ; i < n; i++) { scanf("%d", &stack[i]); } for (int i = 0 ; i < n; i++) { printf("%d\n", dis [stack[i]-1]); } } int sumofstack (int s[], int n); int t = 0 ; for (int i = 0 ; i <= n; i++) { t = t + s[i]; } } return t;
Please review my code here in C... there are errors occurring and I'm not sure why.
Input will begin with a line containing 1 integer, n (1 ≤ n ≤ 200,000), representing the number of exhibits
in the park (including the entrance). The following line contains 2 integers, i and m (i = 1; 1 ≤ m ≤
5,000), representing the ID of the entrance and the number of monkeys at the entrance. Each of the
following 2n - 2 lines will contain a path description recorded by our employee. If this is the first time
the employee used the path, then the line will contain two integers, i and m (2 ≤ i ≤ n; 1 ≤ m ≤ 5,000),
representing the ID of the destination exhibit and the monkeys at the destination exhibit respectively. If
this is the second time the path is used, then the line will contain the integer -1 instead, since the ID and
number of monkeys were already recorded. You can assume that the monkeys don’t move between
exhibits.
Output should contain v lines. Each line will contain a corresponding integer representing the number of
unique monkeys seen in the corresponding visitor’s park visit. The order of the output should correspond
to the order of the input.
Example:
Sample input:
4
1 10
2 13
4 25
-1
3 6
-1
-1
3
4
3
2
Output:
48
29
23
Sample input:
5
1 1
2 2
3 3
-1
-1
4 4
5 5
-1
-1
2
3
5
Output:
6
10
Code is below:
#include<stdio.h>
#include<stdlib.h>
int sumofstack(int s[], int n);
int main()
{
int n;
scanf("%d", &n); int i=0, a,c, stack [n], p = 0 ; int dis[n]; while (i<( (2*n)-1)) {
scanf("%d", &a);
if ( a > 0 )
{
scanf("%d", &c); stack[p]=c;
dis[a=1]=sumofstack(stack,p);
p++;
else {
p--;
}
i++;
}
scanf("%d", &n);
for (int i = 0 ; i < n; i++)
{
scanf("%d", &stack[i]);
} for (int i = 0 ; i < n; i++) {
printf("%d\n", dis [stack[i]-1]);
}
}
int sumofstack (int s[], int n);
int t = 0 ;
for (int i = 0 ; i <= n; i++) {
t = t + s[i];
}
} return t;
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 5 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)