SHARE
TWEET

Booklist.cpp

a guest Oct 21st, 2016 25 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top