Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. int main()
  2. {
  3.    
  4.     int i;
  5.     int current_total_book;                 /* holds the size of total book */
  6.    
  7.     int total_number_of_shelves;
  8.     scanf("%d", &total_number_of_shelves);
  9.    
  10.     int total_number_of_queries;
  11.     scanf("%d", &total_number_of_queries);
  12.    
  13.     /* initial size of total book */
  14.     current_total_book = 110;
  15.     /* initializing the dynamic arrays */
  16.     total_number_of_pages = malloc( total_number_of_shelves * sizeof(int*) );
  17.     total_number_of_books = malloc( total_number_of_shelves * sizeof(int) );
  18.     for( i = 0; i < total_number_of_shelves; i++ ){
  19.         total_number_of_books[i] = 0;
  20.     }
  21.  
  22.     while (total_number_of_queries--) {
  23.         int type_of_query;
  24.         scanf("%d", &type_of_query);
  25.        
  26.         if (type_of_query == 1) {
  27.             /*
  28.              * Process the query of first type here.
  29.              */
  30.             int x, y;
  31.             scanf("%d %d", &x, &y);
  32.             int nb;
  33.             total_number_of_books[x]++;
  34.             nb = total_number_of_books[x];
  35.            
  36.             total_number_of_pages[x] = realloc( total_number_of_pages[x], nb * sizeof( int ) );
  37.            
  38.             /* put the number of pages y into a shelf x,
  39.              * while also increasing the total number of books in shelf x
  40.              */
  41.             total_number_of_pages[x][nb - 1] = y;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement