Guest User

Booklist.cpp

a guest
Oct 21st, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. /*
  2.  Created By: Malvika Joshi
  3.  Problem: BOOKLIST
  4.  Link: http://opc.iarcs.org.in/index.php/problems/BOOKLIST
  5. */
  6.  
  7. #include <iostream>
  8. #include <set>
  9.  
  10. using namespace std;
  11.  
  12. int main(){
  13.  
  14.     int nbooks;
  15.     cin >> nbooks;
  16.  
  17.     int booklist[nbooks];
  18.  
  19.     for(int i = 0;i < nbooks;i++){
  20.         cin >>booklist[i];
  21.     }
  22.  
  23.     int n;
  24.     cin >> n;
  25.  
  26.     set<int> sorted;
  27.     int order[n];
  28.  
  29.     int newentry;
  30.  
  31.     for(int count = 0; count < n; count++){
  32.         cin >> newentry;
  33.         for(set<int>::iterator i = sorted.begin() ; i!=sorted.end();i ++){
  34.             if(*i <= newentry){
  35.                 newentry++;
  36.             }else{
  37.                 break;
  38.             }
  39.         }
  40.         sorted.insert(newentry);
  41.         order[count] = newentry;
  42.     }
  43.  
  44.     for(int i  = 0;i < n;i ++){
  45.         cout << booklist[order[i] - 1] << endl;
  46.     }
  47.  
  48.     return 0;
  49. }
Add Comment
Please, Sign In to add comment