Guest User

Little Monk and Goblet of Fire

a guest
Apr 6th, 2019
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. //whats wrong here
  2. //i am using brute force.
  3. /*
  4. input:
  5. 14
  6. E 1 1
  7. E 2 1
  8. E 1 2
  9. E 2 2
  10. E 1 3
  11. E 3 1
  12. E 3 2
  13. D
  14. D
  15. D
  16. D
  17. D
  18. D
  19. D
  20.  
  21. output://incorrect
  22. 1 3
  23. 1 2
  24. 1 1
  25. 2 2
  26. 2 1
  27. 3 2
  28. 3 1
  29.  
  30. //should be
  31. 1 1
  32. 1 2
  33. 1 3
  34. 2 1
  35. 2 2
  36. 3 1
  37. 3 2
  38.  
  39. */
  40.  
  41. #include <bits/stdc++.h>
  42. using namespace std;
  43. typedef long long ll;
  44. #define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  45.  
  46. int main(){
  47.     FASTER;
  48.     int n;cin>>n;
  49.     list<pair<int,int> > lst;
  50.     for(int i=0;i<n;i++){
  51.         char c;cin>>c;
  52.         if(c=='E'){
  53.             int sc,ro;cin>>sc>>ro;
  54.             if(lst.size()<=1)
  55.                 lst.push_back({sc,ro});
  56.             else{
  57.                 int flg=1;
  58.                 for(auto it=lst.begin();it!=lst.end();it++){
  59.                     if(sc==(it->first)){
  60.                         flg=0;
  61.                         lst.insert(it,{sc,ro});
  62.                         break;
  63.                     }
  64.                 }
  65.                 if(flg)lst.push_back({sc,ro});
  66.             }
  67.         }else{
  68.             cout<<(lst.front()).first<<" "<<(lst.front()).second<<"\n";
  69.             lst.pop_front();
  70.         }
  71.     }
  72. }
Add Comment
Please, Sign In to add comment