Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cstring>
  4. #include<vector>
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8.  
  9. struct activity{
  10.     int start;
  11.     int end;
  12. };
  13.  
  14. bool compareByStart(const activity &a, const activity &b){
  15.     return a.start < b.start;
  16. }
  17.  
  18.  
  19. int main(){
  20.  
  21.     int T;
  22.     cin >> T;
  23.     for(int z = 0; z < T; z++){
  24.         int N;
  25.         cin >> N;
  26.         vector<activity> array;
  27.         string schedule = "";
  28.         int C_end = 0, J_end = 0;
  29.         int not_ok = 1;
  30.  
  31.         for(int i = 0; i < N; i++){
  32.             activity a;
  33.             cin >> a.start >> a.end;
  34.             array.push_back(a);
  35.         }
  36.  
  37.         sort(array.begin(), array.end(), compareByStart);
  38.  
  39.         cout << "Case #" << z + 1 << ": ";
  40.         schedule += "C";
  41.         C_end = array[0].end;
  42.         for(int i = 1; i < array.size(); i++){
  43.             if(array[i].start >= C_end){
  44.                 schedule += "C";
  45.                 C_end = array[i].end;
  46.             }
  47.             else{
  48.                 if(array[i].start >= J_end){
  49.                     schedule += "J";
  50.                     J_end = array[i].end;
  51.                 }
  52.                 else{
  53.                     not_ok = 0;
  54.                     cout << "IMPOSSIBLE\n";
  55.                     break;
  56.                 }
  57.             }
  58.         }
  59.  
  60.         if(not_ok == 0){
  61.             continue;
  62.         }
  63.         else{
  64.             cout << schedule << "\n";
  65.         }        
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement