-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_pointer.c
41 lines (38 loc) · 1.1 KB
/
library_pointer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<stdio.h>
#include<string.h>
int main()
{
int total_number_of_books[100] = {0}; //total number of books in each selves
int total_number_of_shelves;
int total_number_of_pages[100][100] = {0}; // Number of pages in each selves on each book number
int *ptr_books = total_number_of_books;
int *ptr_pages = total_number_of_pages;
scanf("%d", &total_number_of_shelves);
int total_number_of_queries;
scanf("%d", &total_number_of_queries);
while (total_number_of_queries--)
{
int type_of_query;
scanf("%d", &type_of_query);
if (type_of_query == 1)
{
int x, y;
scanf("%d %d", &x, &y);
*(ptr_books + x) += 1;
*(ptr_pages + x * 100 + *(ptr_books + x)-1) = y;
}
else if (type_of_query == 2)
{
int x, y;
scanf("%d %d", &x, &y);
printf("%d\n", *(ptr_pages + x * 100 + y));
}
else
{
int x;
scanf("%d", &x);
printf("%d\n",*(ptr_books +x));
}
}
return 0;
}